For stdio and perror using apps it costs us a small amount of memory. For stdio
using apps in general it's free, and for non stdio apps using itoa and not
sucking in the 32bit maths helpers its a big saving.
/*
- * Internal wrapper for ltostr. Ought to go away
+ * Internal wrapper (in theory) but used in various places it's helpful
*/
#include <stdlib.h>
/*********************** xitoa.c ***************************/
-char *_itoa(int i)
+
+/* Don't go via long - the long version is expensive on an 8bit processor and
+ can often be avoided */
+
+static char buf[7];
+
+char *_uitoa(int i)
{
- return _ltoa((long)i);
+ char *p = buf + sizeof(buf);
+ int c;
+
+ *--p = '\0';
+ do {
+ c = i % 10;
+ i /= 10;
+ *--p = '0' + c;
+ } while(i);
+ return p;
+}
+
+char *_itoa(int i) {
+ char *p;
+ if (i >= 0)
+ return _uitoa(i);
+ p = _uitoa(-i);
+ *--p = '-';
+ return p;
}