diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-19 14:07:01 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-19 14:07:01 +0200 |
commit | 0d2f7645c3fb45d83497faf2a4b6fff8c3f175d1 (patch) | |
tree | a9038fce4cf81556fbdd5589caee8f4e9bfc5185 /src/user/lib/libc | |
parent | 499ca6c243b05da176a2d4bd9a2317f0b28afc7f (diff) | |
download | TCE-0d2f7645c3fb45d83497faf2a4b6fff8c3f175d1.tar.gz TCE-0d2f7645c3fb45d83497faf2a4b6fff8c3f175d1.zip |
Added string class for FWIK.
Diffstat (limited to 'src/user/lib/libc')
-rw-r--r-- | src/user/lib/libc/include/string.h | 3 | ||||
-rw-r--r-- | src/user/lib/libc/std/stdio.c | 40 | ||||
-rw-r--r-- | src/user/lib/libc/std/string.c | 40 |
3 files changed, 43 insertions, 40 deletions
diff --git a/src/user/lib/libc/include/string.h b/src/user/lib/libc/include/string.h index fbe3ade..54fdf7a 100644 --- a/src/user/lib/libc/include/string.h +++ b/src/user/lib/libc/include/string.h @@ -18,6 +18,9 @@ char *strchr(const char *str, int c); char *strcat(char *dest, const char *src); int strcmp(const char *s1, const char *s2); +char* format_int(char* buf, int number); +char* format_hex(char *buf, unsigned v); + #ifdef __cplusplus } } #endif diff --git a/src/user/lib/libc/std/stdio.c b/src/user/lib/libc/std/stdio.c index 3595622..da2f094 100644 --- a/src/user/lib/libc/std/stdio.c +++ b/src/user/lib/libc/std/stdio.c @@ -20,46 +20,6 @@ void fprintf(FILE f, char* format, ...) { va_end(ap); } -// INTERNAL, FOR FORMATTING - -static char* format_int(char* buf, int number) { - if (number == 0) { - *(buf++) = '0'; - return buf; - } - if (number < 0) { - *(buf++) = '-'; - number = 0 - number; - } - - int order = 0, temp = number, i; - char numbers[] = "0123456789"; - while (temp > 0) { - order++; - temp /= 10; - } - - for (i = order; i > 0; i--) { - buf[i - 1] = numbers[number % 10]; - number /= 10; - } - return buf + order; -} - -static char* format_hex(char *buf, unsigned v) { - *(buf++) = '0'; - *(buf++) = 'x'; - - int i; - char hexdigits[] = "0123456789ABCDEF"; - for (i = 0; i < 8; i++) { - *(buf++) = hexdigits[v >> 28]; - v = v << 4; - } - return buf; -} - - // FUNCTIONS void fprint(FILE f, char *s) { diff --git a/src/user/lib/libc/std/string.c b/src/user/lib/libc/std/string.c index 5a41b7e..d8e4a48 100644 --- a/src/user/lib/libc/std/string.c +++ b/src/user/lib/libc/std/string.c @@ -79,3 +79,43 @@ uint16_t *memsetw(uint16_t *dest, uint16_t val, int count) { } return dest; } + + +// Formatting + +char* format_int(char* buf, int number) { + if (number == 0) { + *(buf++) = '0'; + return buf; + } + if (number < 0) { + *(buf++) = '-'; + number = 0 - number; + } + + int order = 0, temp = number, i; + char numbers[] = "0123456789"; + while (temp > 0) { + order++; + temp /= 10; + } + + for (i = order; i > 0; i--) { + buf[i - 1] = numbers[number % 10]; + number /= 10; + } + return buf + order; +} + +char* format_hex(char *buf, unsigned v) { + *(buf++) = '0'; + *(buf++) = 'x'; + + int i; + char hexdigits[] = "0123456789ABCDEF"; + for (i = 0; i < 8; i++) { + *(buf++) = hexdigits[v >> 28]; + v = v << 4; + } + return buf; +} |