diff --git a/src/printf.c b/src/printf.c index ff86363..e1e51be 100644 --- a/src/printf.c +++ b/src/printf.c @@ -345,6 +345,34 @@ } +//printf %p +static int32_t fsh_p(rtprintf_output_handler_t output_handler, void *user, va_list *arg, rtformat_specifier_t *s) +{ + int32_t rv = 0; + + const char charset[] = "0123456789abcdef"; + + char str[32]; + char* const str_end = str + sizeof(str); + + uintptr_t val = va_arg(*arg, uintptr_t); + + char *ptr = str_end; + for(uint32_t i = 0; i < sizeof(uintptr_t) * 2; i++) + { + *--ptr = charset[val & 0xF]; + val >>= 4; + } + + *--ptr = 'x'; + *--ptr = '0'; + + OUTPUT_CHARS(user, ptr, sizeof(uintptr_t) * 2); + + return rv; +} + + /* //print %r - fixed point positive (number of fraction bits precedes the value in the variable argument list) @@ -507,8 +535,8 @@ */ -static char l_fs_chars[16] = "duxXocs"; -static rtformat_specifier_handler_t l_fs_handlers[sizeof(l_fs_chars)] = {fsh_d, fsh_u, fsh_x, fsh_x_cap, fsh_o, fsh_c, fsh_s}; +static char l_fs_chars[16] = "duxXocsp"; +static rtformat_specifier_handler_t l_fs_handlers[sizeof(l_fs_chars)] = {fsh_d, fsh_u, fsh_x, fsh_x_cap, fsh_o, fsh_c, fsh_s, fsh_p}; static inline const char* parse_format_specifier(const char *str, rtformat_specifier_t *s)