diff options
author | Raphael Herouart <rherouart@google.com> | 2023-06-15 17:06:16 +0000 |
---|---|---|
committer | Raphaël Hérouart <rherouart@google.com> | 2023-06-16 20:35:24 +0000 |
commit | e7915ec71702606141925848dedc766fb54efe37 (patch) | |
tree | c7bcb8028c09c87fd4ea49b58b2736a18648bb4f /lib | |
parent | 6bf8ebd41b84c0214dcc8eb6343aa69c3607700d (diff) | |
download | common-e7915ec71702606141925848dedc766fb54efe37.tar.gz |
lib/libc: Update formatting for printf
- indirect width specification via %*s of %*d or alike was not supported
- Passing (NULL, 0, ...) to snprintf to know formatted string length
was not supported
These are necessary for running kernel Benchmarks
Bug: None
Change-Id: I229583854168298ccb7e31cff818f58a378cdb30
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/printf.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/libc/printf.c b/lib/libc/printf.c index 9723196e..178adf93 100644 --- a/lib/libc/printf.c +++ b/lib/libc/printf.c @@ -114,10 +114,13 @@ int vsnprintf(char *str, size_t len, const char *fmt, va_list ap) args.pos = 0; wlen = _printf_unfiltered_engine(&_vsnprintf_output, (void *)&args, fmt, ap); - if (args.pos >= len) - str[len-1] = '\0'; - else - str[wlen] = '\0'; + if(len > 0) { + if (args.pos >= len) + str[len-1] = '\0'; + else + str[wlen] = '\0'; + } + return wlen; } @@ -564,6 +567,18 @@ next_format: uc = va_arg(ap, unsigned int); OUTPUT_CHAR(uc); break; + case '*': + { + /* indirect format */ + int f = va_arg(ap, int); + if(f < 0) { + format_num = (unsigned int) (-f); + flags |= LEFTFORMATFLAG; + } else { + format_num = (unsigned int) (f); + } + goto next_format; + } case 's': s = va_arg(ap, const char *); if (s == 0) |