aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/lib/string.c')
-rw-r--r--src/kernel/lib/string.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c
index f07697d..ef746d6 100644
--- a/src/kernel/lib/string.c
+++ b/src/kernel/lib/string.c
@@ -35,22 +35,19 @@ char *strcpy(char *dest, const char *src) {
return dest;
}
-char *itoa(int i, char b[]) {
- char const digit[] = "0123456789";
- char *p = b;
- if (i < 0) {
- *p++ = '-';
- i *= -1;
+void *itoa(int i, char *b, int base) {
+ int temp_i;
+ temp_i = i;
+ int stringLen = 1;
+
+ while ((int) temp_i / base != 0) {
+ temp_i = (int) temp_i / base;
+ stringLen++;
}
- int shifter = i;
- do {
- ++p;
- shifter = shifter / 10;
- } while (shifter);
- *p = '\0';
+
+ temp_i = i;
do {
- *--p = digit[i % 10];
- i = i / 10;
- } while (i);
- return b;
+ *(b + stringLen - 1) = (temp_i % base) + '0';
+ temp_i = (int) temp_i / base;
+ } while (stringLen--);
} \ No newline at end of file