diff options
author | Freya Murphy <freya@freyacat.org> | 2025-04-16 16:48:40 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-04-16 16:48:40 -0400 |
commit | 01ab373aac3ef679ba0d4d89568b189b94936075 (patch) | |
tree | ee5412b89bed6b4e3c6c02d7c8bf6cb6d651d09e | |
parent | add support for cpu feature checking, see, and avx (diff) | |
download | comus-01ab373aac3ef679ba0d4d89568b189b94936075.tar.gz comus-01ab373aac3ef679ba0d4d89568b189b94936075.tar.bz2 comus-01ab373aac3ef679ba0d4d89568b189b94936075.zip |
add binary radix (%b) to printf
-rw-r--r-- | kernel/lib/kprintf.c | 10 | ||||
-rw-r--r-- | user/lib/printf.c | 9 |
2 files changed, 19 insertions, 0 deletions
diff --git a/kernel/lib/kprintf.c b/kernel/lib/kprintf.c index c2e25fd..269318f 100644 --- a/kernel/lib/kprintf.c +++ b/kernel/lib/kprintf.c @@ -1,3 +1,4 @@ +#include "lib/kio.h" #include <lib.h> #include <comus/drivers/uart.h> #include <comus/drivers/term.h> @@ -217,6 +218,9 @@ static void get_radix(char spec, options_t *opts) case 'o': opts->radix = 8; break; + case 'b': + opts->radix = 2; + break; default: opts->radix = 10; break; @@ -281,6 +285,10 @@ static int printf_lltoa(char *buf, options_t *opts, bool is_neg, // radix specifier if (opts->hash) { + if (opts->radix == 2) { + *(buf++) = 'b'; + *(buf++) = '0'; + } if (opts->radix == 8) { *(buf++) = 'o'; *(buf++) = '0'; @@ -433,6 +441,7 @@ static void do_printf(context_t *ctx, va_list args) case 'd': case 'i': case 'u': + case 'b': case 'o': case 'x': case 'X': @@ -480,6 +489,7 @@ static void do_printf(context_t *ctx, va_list args) // unsigned int case 'p': case 'u': + case 'b': case 'o': case 'x': case 'X': diff --git a/user/lib/printf.c b/user/lib/printf.c index 89806da..4d20263 100644 --- a/user/lib/printf.c +++ b/user/lib/printf.c @@ -224,6 +224,9 @@ static void get_radix(char spec, options_t *opts) case 'o': opts->radix = 8; break; + case 'b': + opts->radix = 2; + break; default: opts->radix = 10; break; @@ -288,6 +291,10 @@ static int printf_lltoa(char *buf, options_t *opts, bool is_neg, // radix specifier if (opts->hash) { + if (opts->radix == 2) { + *(buf++) = 'b'; + *(buf++) = '0'; + } if (opts->radix == 8) { *(buf++) = 'o'; *(buf++) = '0'; @@ -440,6 +447,7 @@ static void do_printf(context_t *ctx, va_list args) case 'd': case 'i': case 'u': + case 'b': case 'o': case 'x': case 'X': @@ -487,6 +495,7 @@ static void do_printf(context_t *ctx, va_list args) // unsigned int case 'p': case 'u': + case 'b': case 'o': case 'x': case 'X': |