diff options
author | johannst <johannes.stoelp@gmail.com> | 2021-04-17 23:41:52 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2021-04-17 23:41:52 +0200 |
commit | 1bcaa7aceefad99c7bda9cb7bf6fcc5b48b53a75 (patch) | |
tree | 5a8a474f9bab158499322aa5a7cde09d2b678885 /lib | |
parent | 26088bf37ef85681cf2158fdff82233b1b0c9bfd (diff) | |
download | dynld-1bcaa7aceefad99c7bda9cb7bf6fcc5b48b53a75.tar.gz dynld-1bcaa7aceefad99c7bda9cb7bf6fcc5b48b53a75.zip |
fmt: add support for %c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/src/fmt.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/src/fmt.c b/lib/src/fmt.c index b0840de..56d95ed 100644 --- a/lib/src/fmt.c +++ b/lib/src/fmt.c @@ -11,7 +11,7 @@ static const char* num2dec(char* buf, unsigned long len, unsigned long long num) } while (num > 0 && pbuf != buf) { - char d = (char)(num % 10) + '0'; + char d = (char)(num % 10) + '0'; *(--pbuf) = d; num /= 10; } @@ -81,6 +81,10 @@ int vfmt(char* buf, unsigned long len, const char* fmt, va_list ap) { const char* ptr = num2hex(scratch, sizeof(scratch), val); puts(ptr); } break; + case 'c': { + char c = va_arg(ap, int); // By C standard, value passed to varg smaller than `sizeof(int)` will be converted to int. + put(c); + } break; case 's': { const char* ptr = va_arg(ap, const char*); puts(ptr); |