summaryrefslogtreecommitdiffstats
path: root/lib/itoa.c
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2025-07-30 14:32:01 -0400
committerJon Santmyer <jon@jonsantmyer.com>2025-07-30 14:32:01 -0400
commitb905869a35f062a4e5072f10bec3a2ba3db0e365 (patch)
tree0666691804878857b4bb07daca8a54f5ddb8ae0b /lib/itoa.c
downloadjove-kernel-b905869a35f062a4e5072f10bec3a2ba3db0e365.tar.gz
jove-kernel-b905869a35f062a4e5072f10bec3a2ba3db0e365.tar.bz2
jove-kernel-b905869a35f062a4e5072f10bec3a2ba3db0e365.zip
working userland with some invoke syscalls
Diffstat (limited to 'lib/itoa.c')
-rw-r--r--lib/itoa.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/itoa.c b/lib/itoa.c
new file mode 100644
index 0000000..57f0c22
--- /dev/null
+++ b/lib/itoa.c
@@ -0,0 +1,32 @@
+#include "string.h"
+
+int
+ltostr(char *s, int size, unsigned long l, bool sign, int radix)
+{
+ unsigned wsize = 0;
+ unsigned digits = 0;
+ if((long)l < 0 && sign) {
+ l = -((long)l);
+ if(size > wsize && s != 0) s[wsize] = '-';
+ wsize++;
+ }
+
+ for(unsigned long lv = l; lv != 0; lv /= radix) {
+ digits++;
+ }
+
+ if(digits-- == 0) {
+ if(size > wsize && s != 0) s[wsize] = '0';
+ wsize++;
+ }
+
+ for(unsigned long lv = l; lv != 0; lv /= radix) {
+ int digit = lv % radix;
+ if(size > digits - wsize && s != 0) {
+ s[digits - wsize] = (digit >= 10 ? (digit + 'a' - 10) : digit + '0');
+ }
+ wsize++;
+ }
+ if(size > wsize && s != 0) s[wsize] = 0;
+ return ++wsize;
+}