summaryrefslogtreecommitdiffstats
path: root/lib/ltostr.c
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2024-03-11 21:30:31 -0400
committerJon Santmyer <jon@jonsantmyer.com>2024-03-11 21:30:31 -0400
commitd1ff7bcc91886626dc9060ec5fb67ee102ab7c1d (patch)
tree8f0b5cd8aad31089131785dc6e37b659490f9955 /lib/ltostr.c
downloadjove-kernel-d1ff7bcc91886626dc9060ec5fb67ee102ab7c1d.tar.gz
jove-kernel-d1ff7bcc91886626dc9060ec5fb67ee102ab7c1d.tar.bz2
jove-kernel-d1ff7bcc91886626dc9060ec5fb67ee102ab7c1d.zip
usermode capable kernel with logging syscall
Diffstat (limited to 'lib/ltostr.c')
-rw-r--r--lib/ltostr.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/ltostr.c b/lib/ltostr.c
new file mode 100644
index 0000000..e28be31
--- /dev/null
+++ b/lib/ltostr.c
@@ -0,0 +1,26 @@
+#include "format.h"
+
+size_t
+ltostr(char *s, size_t limit, unsigned long l, bool sgn, int radix)
+{
+ size_t si = 0;
+ size_t digits = 0;
+ if((long)l < 0 && sgn) {
+ l = -((long)l);
+ s[0] = '-';
+ }
+ for(unsigned long lv = l; lv != 0; lv /= radix)
+ digits++;
+ digits = digits > limit ? limit : digits;
+
+ if(digits-- == 0)
+ s[si++] = '0';
+ for(unsigned long lv = l; lv != 0; lv /= radix)
+ {
+ if(si >= limit) return si;
+ int digit = lv % radix;
+ s[(digits - si)] = (digit >= 10 ? (digit + 'a' - 10) : digit + '0');
+ si++;
+ }
+ return si;
+}