nuttx/libs/libc/stdio
likun17 89a3f28a76 lib_libvsprintf.c:Add buffer data type conversion interface.
Signed-off-by: likun17 <likun17@xiaomi.com>
2024-09-19 11:44:47 +08:00
..
CMakeLists.txt lib_libvsprintf.c:Add buffer data type conversion interface. 2024-09-19 11:44:47 +08:00
Kconfig libc/stdio: changed LIBC_NL_ARGMAX default value to 9 2023-08-03 19:07:22 -07:00
lib_asprintf.c
lib_clearerr.c stdio: Implement [clearerr|putc|fflush]_unlocked 2023-10-29 17:09:18 +02:00
lib_dprintf.c
lib_dtoa_data.c
lib_dtoa_engine.c toolchain/ghs: Fix green hills toolchain build Vela MIN_MANT error 2024-08-19 10:37:54 +08:00
lib_dtoa_engine.h
lib_fclose.c stdio/file: unify group file list to common single queue 2024-03-18 19:32:49 +08:00
lib_feof.c
lib_ferror.c
lib_fflush.c stdio: Implement [clearerr|putc|fflush]_unlocked 2023-10-29 17:09:18 +02:00
lib_fgetc.c libs/libc: support unlock version for fread/fwrite/fputc/fgetc/... 2023-09-06 15:08:24 +03:00
lib_fgetpos.c
lib_fgets.c libs/libc: support unlock version for fread/fwrite/fputc/fgetc/... 2023-09-06 15:08:24 +03:00
lib_fgetwc.c wchar/fgetwc: fix the return value truncate error 2024-08-21 02:57:43 +08:00
lib_fileno.c libc: add support for custom streams with fopencookie() 2023-10-18 21:13:01 +08:00
lib_fmemopen.c libc: add support for memory buffer stream with fmemopen() 2023-10-27 08:55:24 +08:00
lib_fopen.c fdcheck: update fdcheck impl 2024-04-11 10:45:44 +08:00
lib_fopencookie.c libc: add support for custom streams with fopencookie() 2023-10-18 21:13:01 +08:00
lib_fprintf.c
lib_fputc.c libc/stdio: Remove bforce from lib_fflush[_unlocked] 2023-10-29 17:09:18 +02:00
lib_fputs.c libc/stdio: Remove bforce from lib_fflush[_unlocked] 2023-10-29 17:09:18 +02:00
lib_fputwc.c libc/fputwc: fix the return value truncated from stdio interface 2024-08-21 02:57:43 +08:00
lib_fputws.c libs/libc/wchar: add fputws implementation 2023-09-22 08:51:07 +08:00
lib_fread.c libs/libc: support unlock version for fread/fwrite/fputc/fgetc/... 2023-09-06 15:08:24 +03:00
lib_freopen.c libc/stdio: Remove bforce from lib_fflush[_unlocked] 2023-10-29 17:09:18 +02:00
lib_fscanf.c
lib_fseek.c
lib_fseeko.c libc: add support for custom streams with fopencookie() 2023-10-18 21:13:01 +08:00
lib_fsetpos.c
lib_ftell.c
lib_ftello.c libc: add support for custom streams with fopencookie() 2023-10-18 21:13:01 +08:00
lib_fwrite.c libs/libc: support unlock version for fread/fwrite/fputc/fgetc/... 2023-09-06 15:08:24 +03:00
lib_getc.c libs/libc: support unlock version for fread/fwrite/fputc/fgetc/... 2023-09-06 15:08:24 +03:00
lib_getchar.c libs/libc: support unlock version for fread/fwrite/fputc/fgetc/... 2023-09-06 15:08:24 +03:00
lib_getdelim.c libc/stdio: Change FILE buffer field from "unsigned char *" to "char *" 2023-10-22 21:18:46 +03:00
lib_gets_s.c
lib_gets.c
lib_getwc.c libs/libc/wchar: add getwc implementation 2023-12-17 01:39:06 -08:00
lib_libbsprintf.c lib_libvsprintf.c:Add buffer data type conversion interface. 2024-09-19 11:44:47 +08:00
lib_libdgets.c
lib_libfflush.c libc/stdio: Remove bforce from lib_fflush[_unlocked] 2023-10-29 17:09:18 +02:00
lib_libfgets.c libc: add support for custom streams with fopencookie() 2023-10-18 21:13:01 +08:00
lib_libfilelock.c
lib_libflushall.c stdio/file: unify group file list to common single queue 2024-03-18 19:32:49 +08:00
lib_libfread_unlocked.c libc/stdio: Change FILE buffer field from "unsigned char *" to "char *" 2023-10-22 21:18:46 +03:00
lib_libfwrite.c libc/stdio: Remove bforce from lib_fflush[_unlocked] 2023-10-29 17:09:18 +02:00
lib_libgetstreams.c nxstyle: covert utf-8 to ascii 2023-07-14 01:24:50 +08:00
lib_libsprintf.c c++ compatibility: rename reserved c++ keywords 'public' and 'this' 2023-09-16 19:45:02 +08:00
lib_libvscanf.c libs/libc/sscanf: Support pointer format 2024-09-15 10:11:42 +08:00
lib_libvsprintf.c nuttx: fix multiple 'FAR', 'CODE' and style issues 2024-08-25 19:22:15 +08:00
lib_open_memstream.c libc: add support for open_memstream 2023-11-29 02:13:19 -08:00
lib_perror.c
lib_printf.c
lib_putc.c stdio: Implement [clearerr|putc|fflush]_unlocked 2023-10-29 17:09:18 +02:00
lib_putchar.c libs/libc: support unlock version for fread/fwrite/fputc/fgetc/... 2023-09-06 15:08:24 +03:00
lib_puts.c libc/stdio: Remove bforce from lib_fflush[_unlocked] 2023-10-29 17:09:18 +02:00
lib_putwc.c wchar/putwc: fix the putwc return value truncate error 2024-08-21 02:57:43 +08:00
lib_putwchar.c stdio: Implement [clearerr|putc|fflush]_unlocked 2023-10-29 17:09:18 +02:00
lib_rdflush_unlocked.c libc: add support for custom streams with fopencookie() 2023-10-18 21:13:01 +08:00
lib_remove.c lib_remove.c:fix code style error 2024-08-20 13:50:15 +08:00
lib_renameat.c
lib_rewind.c
lib_scanf.c
lib_setbuf.c
lib_setbuffer.c
lib_setvbuf.c libc/stdio: Change FILE buffer field from "unsigned char *" to "char *" 2023-10-22 21:18:46 +03:00
lib_snprintf.c c++ compatibility: rename reserved c++ keywords 'public' and 'this' 2023-09-16 19:45:02 +08:00
lib_sprintf.c libc/stdio: Change FILE buffer field from "unsigned char *" to "char *" 2023-10-22 21:18:46 +03:00
lib_sscanf.c
lib_tempnam.c
lib_tmpfile.c
lib_tmpnam.c
lib_ultoa_invert.c
lib_ultoa_invert.h
lib_ungetc.c libc: add support for custom streams with fopencookie() 2023-10-18 21:13:01 +08:00
lib_ungetwc.c wchar/lib_ungetwc: fix the array access out of bounds error 2024-08-21 02:57:43 +08:00
lib_vasprintf.c libc/stdio: Change FILE buffer field from "unsigned char *" to "char *" 2023-10-22 21:18:46 +03:00
lib_vdprintf.c c++ compatibility: rename reserved c++ keywords 'public' and 'this' 2023-09-16 19:45:02 +08:00
lib_vfprintf.c c++ compatibility: rename reserved c++ keywords 'public' and 'this' 2023-09-16 19:45:02 +08:00
lib_vfscanf.c c++ compatibility: rename reserved c++ keywords 'public' and 'this' 2023-09-16 19:45:02 +08:00
lib_vprintf.c
lib_vscanf.c
lib_vsnprintf.c c++ compatibility: rename reserved c++ keywords 'public' and 'this' 2023-09-16 19:45:02 +08:00
lib_vsprintf.c libc/stdio: Change FILE buffer field from "unsigned char *" to "char *" 2023-10-22 21:18:46 +03:00
lib_vsscanf.c libc/stdio: Change FILE buffer field from "unsigned char *" to "char *" 2023-10-22 21:18:46 +03:00
lib_wrflush_unlocked.c libc/stdio: Remove bforce from lib_fflush[_unlocked] 2023-10-29 17:09:18 +02:00
Make.defs lib_libvsprintf.c:Add buffer data type conversion interface. 2024-09-19 11:44:47 +08:00
README.md lib_libvsprintf.c:Add buffer data type conversion interface. 2024-09-19 11:44:47 +08:00

lib_libbsprintf

This function is mainly used to output the contents of the input structure. Most standards follow the standards of printf and scanf. For detailed parameters, see:

  1. https://en.cppreference.com/w/c/io/fprintf
  2. https://en.cppreference.com/w/c/io/fscanf
  • special:
    1. Float use %hf, and double for all others.
    2. The char array is specified with %.xs. for example: "char t[30]" is specified with "%.30s", char a [20] - " %.20s "
    3. "%u" is unsigned int.
    4. "%d" is int.
    5. When using %f to format a double data type, the double is truncated to 6 decimal places by default.
    6. It is recommended that the "char[]" array be placed at the end of the structure to prevent parameter configuration errors such as "%.20s" from causing problems in parsing the entire buffer.
  • demo
    1. struct:
    begin_packed_struct
    struct test
    {
      uint8_t a;
      uint16_t b;
      uint32_t c;
      int8_t d;
      int16_t e;
      int32_t f;
      float g;
      double h;
      char i[32];
      uint64_t j;
      int64_t k;
      char l;
      unsigned char m;
      short int n;
      unsigned short int o;
      int p;
      unsigned int q;
      long r;
      unsigned long s;
      long long t;
      unsigned long long u;
      size_t v;
      long double w;
    }end_packed_struct;
    
    1. format string:
    const char* sg = "           uint8_t:[%hhu]\n" \
                     "          uint16_t:[%hu]\n" \
                     "          uint32_t:[%u]\n" \
                     "            int8_t:[%hhd]\n" \
                     "           int16_t:[%hd]\n" \
                     "           int32_t:[%d]\n" \
                     "             float:[%hf]\n" \
                     "            double:[%f]\n" \
                     "            char[]:[%.32s]\n" \
                     "          uint64_t:[%lu]\n" \
                     "           int64_t:[%ld]\n" \
                     "              char:[%hhd]\n" \
                     "     unsigned char:[%hhu]\n" \
                     "         short int:[%hd]\n" \
                     "unsigned short int:[%hu]\n" \
                     "               int:[%d]\n" \
                     "      unsigned int:[%u]\n" \
                     "              long:[%ld]\n" \
                     "     unsigned long:[%lu]\n" \
                     "         long long:[%lld]\n" \
                     "unsigned long long:[%llu]\n" \
                     "            size_t:[%uz]\n" \
                     "       long double:[%Lf]\n";
    
    1. use:
    • output to terminal:
    #ifdef CONFIG_FILE_STREAM
     struct lib_stdoutstream_s stdoutstream;
    
     lib_stdoutstream(&stdoutstream, stdout);
    
     flockfile(stdout);
     lib_bsprintf(&stdoutstream.common, sv, &test_v);
     lib_bsprintf(&stdoutstream.common, sg, &test_g);
     funlockfile(stdout);
    #else
     struct lib_rawoutstream_s rawoutstream;
     struct lib_bufferedoutstream_s outstream;
    
     lib_rawoutstream(&rawoutstream, STDOUT_FILENO);
     lib_bufferedoutstream(&outstream, &rawoutstream.common);
    
     lib_bsprintf(&outstream.common, sv, &test_v);
     lib_bsprintf(&outstream.common, sg, &test_g);
    
     lib_stream_flush(&outstream.common);
    #endif