From 53b5476c54e5157fc3c5e48784038b317cf497d9 Mon Sep 17 00:00:00 2001 From: hunt Date: Thu, 25 May 2006 18:49:17 +0000 Subject: 2006-05-25 Martin Hunt * vsprintf.c (_stp_vsnprintf): Change %p to work like libc and automatically insert "0x" before the pointer. --- runtime/vsprintf.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'runtime/vsprintf.c') diff --git a/runtime/vsprintf.c b/runtime/vsprintf.c index ba0bc85a..7abb5dc5 100644 --- a/runtime/vsprintf.c +++ b/runtime/vsprintf.c @@ -295,10 +295,26 @@ int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) break; case 'p': + len = 2*sizeof(void *) + 2; if (field_width == -1) { - field_width = 2*sizeof(void *); + field_width = len; flags |= STP_ZEROPAD; } + if (!(flags & STP_LEFT)) { + while (len < field_width--) { + if (str <= end) + *str = ' '; + ++str; + } + } + if (str <= end) { + *str++ = '0'; + field_width--; + } + if (str <= end) { + *str++ = 'x'; + field_width--; + } str = number(str, end, (unsigned long) va_arg(args, int64_t), 16, field_width, precision, flags); -- cgit