1234567891011121314151617181920212223242526272829 |
- #include <common/stdlib.h>
- const char *ltoa(long input)
- {
-
- static char buffer[21] = {0};
- char *pos = buffer + sizeof(buffer) - 1;
- int neg = input < 0;
- unsigned long n = neg ? -input : input;
- *pos-- = '\0';
- do
- {
- *pos-- = '0' + n % 10;
- n /= 10;
- if (pos < buffer)
- return pos + 1;
- } while (n);
- if (neg)
- *pos-- = '-';
- return pos + 1;
- }
|