fixed missing COMMON from .bss zeroing, using new toolchain and link
[mdlife] / src / libc / stdlib.c
index a6149e9..caed2bc 100644 (file)
@@ -2,8 +2,6 @@
 #include <string.h>
 #include <ctype.h>
 #include <limits.h>
-#include <assert.h>
-#include <alloca.h>
 
 int atoi(const char *str)
 {
@@ -72,10 +70,12 @@ long strtol(const char *str, char **endp, int base)
 
 void itoa(int val, char *buf, int base)
 {
-       static char rbuf[16];
+       char rbuf[16];
        char *ptr = rbuf;
        int neg = 0;
 
+       if(base <= 0) base = 10;
+
        if(val < 0) {
                neg = 1;
                val = -val;
@@ -103,11 +103,41 @@ void itoa(int val, char *buf, int base)
        *buf = 0;
 }
 
+void xtoa(unsigned int val, char *buf)
+{
+       char rbuf[16];
+       char *ptr = rbuf;
+
+       if(val == 0) {
+               *ptr++ = '0';
+       }
+
+       while(val) {
+               unsigned int digit = val & 0xf;
+               *ptr++ = digit < 10 ? (digit + '0') : (digit - 10 + 'a');
+               val >>= 4;
+       }
+
+       ptr--;
+
+       while(ptr >= rbuf) {
+               *buf++ = *ptr--;
+       }
+       *buf = 0;
+}
+
 void utoa(unsigned int val, char *buf, int base)
 {
        static char rbuf[16];
        char *ptr = rbuf;
 
+       if(base == 16) {
+               xtoa(val, buf);
+               return;
+       }
+
+       if(base <= 0) base = 10;
+
        if(val == 0) {
                *ptr++ = '0';
        }