1
0
Fork 0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-01-23 08:35:19 -05:00

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: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
This commit is contained in:
Willy Tarreau 2022-03-21 18:33:09 +01:00 committed by Paul E. McKenney
parent 077d0a3924
commit bd845a193a

View file

@ -163,7 +163,7 @@ char *fgets(char *s, int size, FILE *stream)
/* minimal vfprintf(). It supports the following formats:
* - %[l*]{d,u,c,x}
* - %[l*]{d,u,c,x,p}
* - %s
* - unknown modifiers are ignored.
*/
@ -184,8 +184,12 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
if (escape) {
/* we're in an escape sequence, ofs == 1 */
escape = 0;
if (c == 'c' || c == 'd' || c == 'u' || c == 'x') {
if (lpref) {
if (c == 'c' || c == 'd' || c == 'u' || c == 'x' || c == 'p') {
char *out = tmpbuf;
if (c == 'p')
v = va_arg(args, unsigned long);
else if (lpref) {
if (lpref > 1)
v = va_arg(args, unsigned long long);
else
@ -202,18 +206,22 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
}
switch (c) {
case 'c':
out[0] = v;
out[1] = 0;
break;
case 'd':
i64toa_r(v, tmpbuf);
i64toa_r(v, out);
break;
case 'u':
u64toa_r(v, tmpbuf);
u64toa_r(v, out);
break;
case 'x':
u64toh_r(v, tmpbuf);
break;
default: /* 'c' */
tmpbuf[0] = v;
tmpbuf[1] = 0;
case 'p':
*(out++) = '0';
*(out++) = 'x';
/* fall through */
default: /* 'x' and 'p' above */
u64toh_r(v, out);
break;
}
outstr = tmpbuf;