Commit bd845a19 authored by Willy Tarreau's avatar Willy Tarreau Committed by Paul E. McKenney

tools/nolibc/stdio: add support for '%p' to vfprintf()

%p remains quite useful in test code, and the code path can easily be
merged with the existing "%x" thus only adds ~50 bytes, thus let's
add it.
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
parent 077d0a39
...@@ -163,7 +163,7 @@ char *fgets(char *s, int size, FILE *stream) ...@@ -163,7 +163,7 @@ char *fgets(char *s, int size, FILE *stream)
/* minimal vfprintf(). It supports the following formats: /* minimal vfprintf(). It supports the following formats:
* - %[l*]{d,u,c,x} * - %[l*]{d,u,c,x,p}
* - %s * - %s
* - unknown modifiers are ignored. * - unknown modifiers are ignored.
*/ */
...@@ -184,8 +184,12 @@ int vfprintf(FILE *stream, const char *fmt, va_list args) ...@@ -184,8 +184,12 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
if (escape) { if (escape) {
/* we're in an escape sequence, ofs == 1 */ /* we're in an escape sequence, ofs == 1 */
escape = 0; escape = 0;
if (c == 'c' || c == 'd' || c == 'u' || c == 'x') { if (c == 'c' || c == 'd' || c == 'u' || c == 'x' || c == 'p') {
if (lpref) { char *out = tmpbuf;
if (c == 'p')
v = va_arg(args, unsigned long);
else if (lpref) {
if (lpref > 1) if (lpref > 1)
v = va_arg(args, unsigned long long); v = va_arg(args, unsigned long long);
else else
...@@ -202,18 +206,22 @@ int vfprintf(FILE *stream, const char *fmt, va_list args) ...@@ -202,18 +206,22 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
} }
switch (c) { switch (c) {
case 'c':
out[0] = v;
out[1] = 0;
break;
case 'd': case 'd':
i64toa_r(v, tmpbuf); i64toa_r(v, out);
break; break;
case 'u': case 'u':
u64toa_r(v, tmpbuf); u64toa_r(v, out);
break;
case 'x':
u64toh_r(v, tmpbuf);
break; break;
default: /* 'c' */ case 'p':
tmpbuf[0] = v; *(out++) = '0';
tmpbuf[1] = 0; *(out++) = 'x';
/* fall through */
default: /* 'x' and 'p' above */
u64toh_r(v, out);
break; break;
} }
outstr = tmpbuf; outstr = tmpbuf;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment