aboutsummaryrefslogtreecommitdiff
path: root/src/base/string
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/string')
-rw-r--r--src/base/string/itoa.c23
-rw-r--r--src/base/string/rules.mk1
2 files changed, 24 insertions, 0 deletions
diff --git a/src/base/string/itoa.c b/src/base/string/itoa.c
new file mode 100644
index 0000000..a2910f4
--- /dev/null
+++ b/src/base/string/itoa.c
@@ -0,0 +1,23 @@
+#include "internal.h"
+
+static char *
+kernel(char *s, int x)
+{
+ if(x/10)
+ s = kernel(s, x/10);
+ *s++ = x%10 + '0';
+ return s;
+}
+
+char *
+strĀ·itoa(char *s, int x)
+{
+ if(x<0){
+ *s++ = '-';
+ x=-x;
+ }
+ s = kernel(s, x);
+ *s = '0';
+
+ return s;
+}
diff --git a/src/base/string/rules.mk b/src/base/string/rules.mk
index 0352f54..5fa6c5e 100644
--- a/src/base/string/rules.mk
+++ b/src/base/string/rules.mk
@@ -1,5 +1,6 @@
SRCS_$(d)+=\
$(d)/string/atoi.c\
+ $(d)/string/itoa.c\
$(d)/string/append.c\
$(d)/string/appendf.c\
$(d)/string/clear.c\