diff options
Diffstat (limited to 'src/user/knob/format.c')
-rw-r--r-- | src/user/knob/format.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/user/knob/format.c b/src/user/knob/format.c index f55e857..087f6fd 100644 --- a/src/user/knob/format.c +++ b/src/user/knob/format.c @@ -10,4 +10,22 @@ bool try_sntoi(const char *s, uint32_t n, uint32_t *out) { } *out = calc; return true; +} + +void itosz(uint32_t i, char *out) { + if (!i) { + *(uint16_t *)out = (uint16_t)'0'; + return; + } + bool zero = false; + for (uint32_t m = 1000000000; m; m /= 10) { + uint8_t d = (i / m) % 10; + if (zero) + *(out++) = d + '0'; + else if (d) { + zero = true; + *(out++) = d + '0'; + } + } + *out = '\0'; }
\ No newline at end of file |