summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authordzwdz2022-10-19 15:17:36 +0200
committerdzwdz2022-10-19 15:17:36 +0200
commite4118bb67dee6b4064d196cbe6e1c83cb7d1d586 (patch)
treec19eae356e2437d779af176c855a4a2a0587ea26 /src/shared
parentd98c6dd0954bd753a9150d39364f3866579cf2f0 (diff)
shared/printf: implement %p
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/printf.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/shared/printf.c b/src/shared/printf.c
index a9cd355..5134048 100644
--- a/src/shared/printf.c
+++ b/src/shared/printf.c
@@ -2,6 +2,7 @@
#include <shared/printf.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <stdint.h>
enum lenmod {
LM_int,
@@ -82,6 +83,18 @@ static void output_uint(struct out_state *os, struct mods *m, unsigned long long
output(os, buf + pos, len);
}
+static void output_uint16(struct out_state *os, struct mods *m, unsigned long long n) {
+ size_t len = 1;
+ while (n >> (len * 4) && (len * 4) < (sizeof(n) * 8))
+ len++;
+ padnum(os, m, len, '\0');
+ while (len-- > 0) {
+ char h = '0' + ((n >> (len * 4)) & 0xf);
+ if (h > '9') h += 'a' - '9' - 1;
+ output_c(os, h, 1);
+ }
+}
+
int __printf_internal(const char *fmt, va_list argp,
void (*back)(void*, const char*, size_t), void *backarg)
@@ -176,19 +189,16 @@ int __printf_internal(const char *fmt, va_list argp,
output(&os, s, len);
break;
+ case 'p':
+ output(&os, "0x", 2);
+ output_uint16(&os, &m, (uintptr_t)va_arg(argp, void*));
+ break;
+
case 'x':
if (lm == LM_int) n = va_arg(argp, unsigned int);
else if (lm == LM_long) n = va_arg(argp, unsigned long);
else if (lm == LM_longlong) n = va_arg(argp, unsigned long long);
- len = 1;
- while (n >> (len * 4) && (len * 4) < (sizeof(n) * 8))
- len++;
- padnum(&os, &m, len, '\0');
- while (len-- > 0) {
- char h = '0' + ((n >> (len * 4)) & 0xf);
- if (h > '9') h += 'a' - '9' - 1;
- output_c(&os, h, 1);
- }
+ output_uint16(&os, &m, n);
break;
case 'u':