Summary: Modified the usage logic, mainly introduced lib_get_pathbuffer and lib_put_pathbuffer Signed-off-by: chenrun1 <chenrun1@xiaomi.com> |
||
|---|---|---|
| .. | ||
| CMakeLists.txt | ||
| Kconfig | ||
| lib_asprintf.c | ||
| lib_clearerr.c | ||
| lib_dprintf.c | ||
| lib_dtoa_data.c | ||
| lib_dtoa_engine.c | ||
| lib_dtoa_engine.h | ||
| lib_fclose.c | ||
| lib_feof.c | ||
| lib_ferror.c | ||
| lib_fflush.c | ||
| lib_fgetc.c | ||
| lib_fgetpos.c | ||
| lib_fgets.c | ||
| lib_fgetwc.c | ||
| lib_fileno.c | ||
| lib_fmemopen.c | ||
| lib_fopen.c | ||
| lib_fopencookie.c | ||
| lib_fprintf.c | ||
| lib_fputc.c | ||
| lib_fputs.c | ||
| lib_fputwc.c | ||
| lib_fputws.c | ||
| lib_fread.c | ||
| lib_freopen.c | ||
| lib_fscanf.c | ||
| lib_fseek.c | ||
| lib_fseeko.c | ||
| lib_fsetpos.c | ||
| lib_ftell.c | ||
| lib_ftello.c | ||
| lib_fwrite.c | ||
| lib_getc.c | ||
| lib_getchar.c | ||
| lib_getdelim.c | ||
| lib_gets.c | ||
| lib_gets_s.c | ||
| lib_getwc.c | ||
| lib_libbsprintf.c | ||
| lib_libdgets.c | ||
| lib_libfflush.c | ||
| lib_libfgets.c | ||
| lib_libfilelock.c | ||
| lib_libflushall.c | ||
| lib_libfread_unlocked.c | ||
| lib_libfwrite.c | ||
| lib_libgetstreams.c | ||
| lib_libsprintf.c | ||
| lib_libvscanf.c | ||
| lib_libvsprintf.c | ||
| lib_open_memstream.c | ||
| lib_perror.c | ||
| lib_printf.c | ||
| lib_putc.c | ||
| lib_putchar.c | ||
| lib_puts.c | ||
| lib_putwc.c | ||
| lib_putwchar.c | ||
| lib_rdflush_unlocked.c | ||
| lib_remove.c | ||
| lib_renameat.c | ||
| lib_rewind.c | ||
| lib_scanf.c | ||
| lib_setbuf.c | ||
| lib_setbuffer.c | ||
| lib_setvbuf.c | ||
| lib_snprintf.c | ||
| lib_sprintf.c | ||
| lib_sscanf.c | ||
| lib_tempnam.c | ||
| lib_tmpfile.c | ||
| lib_tmpnam.c | ||
| lib_ultoa_invert.c | ||
| lib_ultoa_invert.h | ||
| lib_ungetc.c | ||
| lib_ungetwc.c | ||
| lib_vasprintf.c | ||
| lib_vdprintf.c | ||
| lib_vfprintf.c | ||
| lib_vfscanf.c | ||
| lib_vprintf.c | ||
| lib_vscanf.c | ||
| lib_vsnprintf.c | ||
| lib_vsprintf.c | ||
| lib_vsscanf.c | ||
| lib_wrflush_unlocked.c | ||
| Make.defs | ||
| README.md | ||
lib_bsprintf
This function is mainly used to output the contents of the input structure. Supports standard formats for printf and scanf. For detailed parameters, see:
- special:
- Float use %hf, "%f" or "%lf" is double, "%Lf" is long double.
- The char array is specified with %.xs. for example: "char t[30]" is specified with "%.30s", char a [20] - " %.20s "
- "%u" is unsigned int.
- "%d" is int.
- When using %f to format a double data type, the double is truncated to 6 decimal places by default.
- 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
- 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;- 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";- 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
lib_bscanf
This function adds a formatted standard scanf string to the structure(lib_bscanf).
-
special:
- Please use %lf for double precision, "%hf" or "%f" for float, long double ("%Lf") is not supported.
- Please use %hhd or %hhu for a single char or unsigned char.
- Use %hd or %hu for short int or unsigned short int.
- When using %s or %c, please specify the length of the char array, such as %32s, %32c.
- %s will check the string for spaces. When there are spaces in the string, it will be truncated. If you want to use string with spaces, please use %{length}c, but make sure that the length of the string can fill the array, otherwise an error will occur.
- %[] collection and %n are not supported.
-
demo
- struct: Same as above
- format string:
#define TOSTR(str) #str #define TONNAME(name) TOSTR(name) #define v_uint8_t 97 #define v_uint16_t 19299 #define v_uint32_t 22155 ...... #define v_l_double -9299.9299929912122464755474 char bflag[] = "%hhu%hu%u%hhd%hd%d%f%lf%32s%llu%lld%hhd%hhu%hd%hu%d%u%ld%lu%lld%llu%zu%ld"; char binput[] = TONNAME(v_uint8_t) \ " " TONNAME(v_uint16_t) \ " " TONNAME(v_uint32_t) \ " " TONNAME(v_int8_t) \ " " TONNAME(v_int16_t) \ " " TONNAME(v_int32_t) \ " " TONNAME(v_float) \ " " TONNAME(v_double) \ " " TONNAME(v_char_arr) \ " " TONNAME(v_uint64_t) \ " " TONNAME(v_int64_t) \ " " TONNAME(v_char) \ " " TONNAME(v_u_char) \ " " TONNAME(v_s_int) \ " " TONNAME(v_u_s_int) \ " " TONNAME(v_int) \ " " TONNAME(v_u_int) \ " " TONNAME(v_long) \ " " TONNAME(v_u_long) \ " " TONNAME(v_l_l) \ " " TONNAME(v_u_l_l) \ " " TONNAME(v_size_t) \ " " TONNAME(v_l_double);- use:
struct test vg; ret = lib_bscanf(binput, bflag, &vg);