baselibc - Add %p format specifier to tinyprintf.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/badc6e99 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/badc6e99 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/badc6e99 Branch: refs/heads/nrf_cputime Commit: badc6e99ad77db4d818cf5ca904a18a028afe8df Parents: 0eed22f Author: Christopher Collins <ccoll...@apache.org> Authored: Tue Mar 28 18:03:55 2017 -0700 Committer: Christopher Collins <ccoll...@apache.org> Committed: Tue Mar 28 18:03:55 2017 -0700 ---------------------------------------------------------------------- libc/baselibc/src/tinyprintf.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/badc6e99/libc/baselibc/src/tinyprintf.c ---------------------------------------------------------------------- diff --git a/libc/baselibc/src/tinyprintf.c b/libc/baselibc/src/tinyprintf.c index e48be4a..7719d80 100644 --- a/libc/baselibc/src/tinyprintf.c +++ b/libc/baselibc/src/tinyprintf.c @@ -52,7 +52,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* This is a smaller implementation of printf-family of functions, * based on tinyprintf code by Kustaa Nyholm. - * The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'. + * The formats supported by this implementation are: + * 'd' 'u' 'c' 's' 'x' 'X' 'p'. * Zero padding and field width are also supported. * If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the * long specifier is also supported. @@ -61,6 +62,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <stdio.h> +#include <inttypes.h> struct param { unsigned char width; /**< field width */ @@ -231,6 +233,7 @@ size_t tfp_format(FILE *putp, const char *fmt, va_list va) char bf[23]; char ch; char lng; + void *v; p.bf = bf; @@ -300,6 +303,16 @@ size_t tfp_format(FILE *putp, const char *fmt, va_list va) ui2a(intarg(lng, 0, &va), &p); written += putchw(putp, &p); break; + case 'p': + v = va_arg(va, void *); + ui2a((uintptr_t)v, &p); + p.base = 16; + p.width = 2 * sizeof(void*); + p.lz = 1; + written += putf(putp, '0'); + written += putf(putp, 'x'); + written += putchw(putp, &p); + break; case 'c': written += putf(putp, (char)(va_arg(va, int))); break;