summaryrefslogtreecommitdiff
path: root/kernel/lib/atox.c
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-04-08 10:39:48 -0400
committerFreya Murphy <freya@freyacat.org>2025-04-08 10:39:48 -0400
commit8a19547957a86bed3f58c9abc1ac218d04698faf (patch)
treeed7ccc6f3a8902915dfe6c9bf763fc45d752b3c4 /kernel/lib/atox.c
parentfmt (diff)
downloadcomus-8a19547957a86bed3f58c9abc1ac218d04698faf.tar.gz
comus-8a19547957a86bed3f58c9abc1ac218d04698faf.tar.bz2
comus-8a19547957a86bed3f58c9abc1ac218d04698faf.zip
break apart c libaray
Diffstat (limited to 'kernel/lib/atox.c')
-rw-r--r--kernel/lib/atox.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/kernel/lib/atox.c b/kernel/lib/atox.c
new file mode 100644
index 0000000..6d3d4cc
--- /dev/null
+++ b/kernel/lib/atox.c
@@ -0,0 +1,29 @@
+#include <lib.h>
+
+#define ATOX(name, type) \
+ type name(const char *s) \
+ { \
+ for (; isspace(*s); s++) \
+ ; \
+ int neg = 0; \
+ switch (*s) { \
+ case '-': \
+ neg = 1; \
+ /* fallthrough */ \
+ case '+': \
+ s++; \
+ break; \
+ } \
+ type num = 0; \
+ for (; *s == '0'; s++) \
+ ; \
+ for (; isdigit(*s); s++) { \
+ num *= 10; \
+ num += *s - '0'; \
+ } \
+ return num * (neg ? -1 : 1); \
+ }
+
+ATOX(atoi, int)
+ATOX(atol, long int)
+ATOX(atoll, long long int)