summaryrefslogtreecommitdiff
path: root/kernel/lib/kprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/lib/kprintf.c')
-rw-r--r--kernel/lib/kprintf.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/kernel/lib/kprintf.c b/kernel/lib/kprintf.c
index 7b1ed71..c2e25fd 100644
--- a/kernel/lib/kprintf.c
+++ b/kernel/lib/kprintf.c
@@ -262,43 +262,44 @@ static int printf_lltoa(char *buf, options_t *opts, bool is_neg,
}
precision = 0;
- // sign
- if (is_neg) {
- *(buf++) = '-';
- } else if (opts->sign) {
- *(buf++) = '+';
- } else if (opts->space) {
- *(buf++) = ' ';
+ // write number
+ if (num == 0) {
+ *(buf++) = '0';
+ }
+ while (num) {
+ if (opts->precision_set && precision++ >= opts->precision)
+ break;
+ *(buf++) = printf_itoc(opts->is_uppercase, num % opts->radix);
+ num /= opts->radix;
+ }
+
+ // print zeros if needed
+ if (opts->width_set && len < opts->width && opts->zero) {
+ while (len++ < opts->width)
+ *(buf++) = '0';
}
// radix specifier
if (opts->hash) {
if (opts->radix == 8) {
- *(buf++) = '0';
*(buf++) = 'o';
+ *(buf++) = '0';
}
if (opts->radix == 16) {
- *(buf++) = '0';
*(buf++) = 'x';
+ *(buf++) = '0';
}
}
- // print zeros if needed
- if (opts->width_set && len < opts->width && opts->zero) {
- while (len++ < opts->width)
- *(buf++) = '0';
+ // sign
+ if (is_neg) {
+ *(buf++) = '-';
+ } else if (opts->sign) {
+ *(buf++) = '+';
+ } else if (opts->space) {
+ *(buf++) = ' ';
}
- // write number
- if (num == 0) {
- *(buf++) = '0';
- }
- while (num) {
- if (opts->precision_set && precision++ >= opts->precision)
- break;
- *(buf++) = printf_itoc(opts->is_uppercase, num % opts->radix);
- num /= opts->radix;
- }
*(buf++) = '\0';
return buf - start;
@@ -333,8 +334,8 @@ static void handle_int_specifier(context_t *ctx, options_t *const opts,
printf_putc(ctx, opts->zero ? '0' : ' ');
}
// number
- for (int i = 0; i < buf_len; i++)
- printf_putc(ctx, buf[i]);
+ for (int i = 1; i <= buf_len; i++)
+ printf_putc(ctx, buf[buf_len - i]);
// right padding
if (opts->left == 1) {
for (int i = 0; i < padding; i++)
@@ -424,7 +425,8 @@ static void do_printf(context_t *ctx, va_list args)
switch (spec) {
case 'p':
opts.len = PRINTF_LEN_SIZE_T;
- opts.width_set = true;
+ opts.width_set = 1;
+ opts.width = sizeof(void *) * 2;
opts.radix = 16;
opts.hash = true;
opts.zero = true;