diff options
Diffstat (limited to 'bsp/AE210P/libc/string')
| -rw-r--r-- | bsp/AE210P/libc/string/Kbuild | 12 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/memcpy.c | 10 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/memmove.c | 17 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/memset.c | 10 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/strcasecmp.c | 30 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/strcat.c | 33 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/strcmp.c | 30 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/strcpy.c | 30 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/strdup.c | 32 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/strlen.c | 23 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/strstr.c | 45 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/strtoul.c | 82 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/strupr.c | 16 | ||||
| -rw-r--r-- | bsp/AE210P/libc/string/wchar.c | 147 |
14 files changed, 517 insertions, 0 deletions
diff --git a/bsp/AE210P/libc/string/Kbuild b/bsp/AE210P/libc/string/Kbuild new file mode 100644 index 0000000000..6aef18c68c --- /dev/null +++ b/bsp/AE210P/libc/string/Kbuild @@ -0,0 +1,12 @@ +lib-y += memcpy.o +lib-y += memmove.o +lib-y += memset.o +lib-y += strcat.o +lib-y += strcasecmp.o +lib-y += strcmp.o +lib-y += strdup.o +lib-y += strlen.o +lib-y += strstr.o +lib-y += strtoul.o +lib-y += strupr.o +lib-y += wchar.o diff --git a/bsp/AE210P/libc/string/memcpy.c b/bsp/AE210P/libc/string/memcpy.c new file mode 100644 index 0000000000..c1334292a3 --- /dev/null +++ b/bsp/AE210P/libc/string/memcpy.c @@ -0,0 +1,10 @@ +#include <string.h> + +__attribute__((used)) +void *memcpy(void *dest, const void *src, size_t n) +{ + while (n--) + *(unsigned char *)dest++ = *(const unsigned char *)src++; + + return dest; +} diff --git a/bsp/AE210P/libc/string/memmove.c b/bsp/AE210P/libc/string/memmove.c new file mode 100644 index 0000000000..02bfbe423d --- /dev/null +++ b/bsp/AE210P/libc/string/memmove.c @@ -0,0 +1,17 @@ +#include <string.h> + +__attribute__((used)) +void *memmove(void *dest, const void *src, size_t n) +{ + char *destp = dest; + const char *srcp = src; + + if (srcp < destp) + while (n--) + destp[n] = srcp[n]; + else + while (n--) + *destp++ = *srcp++; + + return dest; +} diff --git a/bsp/AE210P/libc/string/memset.c b/bsp/AE210P/libc/string/memset.c new file mode 100644 index 0000000000..6cf608b145 --- /dev/null +++ b/bsp/AE210P/libc/string/memset.c @@ -0,0 +1,10 @@ +#include <string.h> + +__attribute__((used)) +void *memset(void *s, int c, size_t n) +{ + while (n--) + *(unsigned char *)s++ = c; + + return s; +} diff --git a/bsp/AE210P/libc/string/strcasecmp.c b/bsp/AE210P/libc/string/strcasecmp.c new file mode 100644 index 0000000000..7e2996e9f4 --- /dev/null +++ b/bsp/AE210P/libc/string/strcasecmp.c @@ -0,0 +1,30 @@ +#include <string.h> + +__attribute__((used)) +int strcasecmp(const char *s1, const char *s2) +{ + while (*s1 == *s2 || (*s1 ^ 0x20) == *s2) { + + if (!*s1) + return 0; + ++s1; + ++s2; + } + + return *(unsigned char *)s1 - *(unsigned char *)s2; +} + +__attribute__((used)) +int strncasecmp(const char *s1, const char *s2, size_t n) +{ + while ((*s1 == *s2 || (*s1 ^ 0x20) == *s2) && --n) { + + if (!*s1) + return 0; + ++s1; + ++s2; + } + + return *(unsigned char *)s1 - *(unsigned char *)s2; +} + diff --git a/bsp/AE210P/libc/string/strcat.c b/bsp/AE210P/libc/string/strcat.c new file mode 100644 index 0000000000..b2121a03fa --- /dev/null +++ b/bsp/AE210P/libc/string/strcat.c @@ -0,0 +1,33 @@ +#include <string.h> + +__attribute__((used)) +char *strcat(char *dest, const char *src) +{ + char *destp = dest; + + while (*destp) + destp++; + + while (*src) + *destp++ = *src++; + + *destp = '\0'; + + return dest; +} + +__attribute__((used)) +char *strncat(char *dest, const char *src, size_t n) +{ + char *destp = dest; + + while (*destp) + destp++; + + while (*src && n--) + *destp++ = *src++; + + *destp = '\0'; + + return dest; +} diff --git a/bsp/AE210P/libc/string/strcmp.c b/bsp/AE210P/libc/string/strcmp.c new file mode 100644 index 0000000000..277bafaaaf --- /dev/null +++ b/bsp/AE210P/libc/string/strcmp.c @@ -0,0 +1,30 @@ +#include <string.h> + +__attribute__((used)) +int strcmp(const char *s1, const char *s2) +{ + while (*s1 == *s2) { + + if (!*s1) + return 0; + ++s1; + ++s2; + } + + return *(unsigned char *)s1 - *(unsigned char *)s2; +} + +__attribute__((used)) +int strncmp(const char *s1, const char *s2, size_t n) +{ + while (*s1 == *s2 && --n) { + + if (!*s1) + return 0; + ++s1; + ++s2; + } + + return *(unsigned char *)s1 - *(unsigned char *)s2; +} + diff --git a/bsp/AE210P/libc/string/strcpy.c b/bsp/AE210P/libc/string/strcpy.c new file mode 100644 index 0000000000..1d9ff003f0 --- /dev/null +++ b/bsp/AE210P/libc/string/strcpy.c @@ -0,0 +1,30 @@ +#include <string.h> + +__attribute__((used)) +char *strcpy(char *dest, const void *src) +{ + char *destp = dest; + char *srcp = (char *)src; + + while (*srcp) + *destp++ = *srcp++; + + *destp = '\0'; + + return dest; +} + +__attribute__((used)) +char *strncpy(char *dest, const void *src, size_t n) +{ + char *destp = dest; + char *srcp = (char *)src; + + while (*srcp && n--) + *destp++ = *srcp++; + + if (n) + *destp = '\0'; + + return dest; +} diff --git a/bsp/AE210P/libc/string/strdup.c b/bsp/AE210P/libc/string/strdup.c new file mode 100644 index 0000000000..ae497f8504 --- /dev/null +++ b/bsp/AE210P/libc/string/strdup.c @@ -0,0 +1,32 @@ +#include <string.h> +#include <stdlib.h> + +__attribute__((used)) +char *strdup(const char *s) +{ + int len = strlen(s); + char *buf = malloc(len + 1); + + if (buf) { + + strncpy(buf, s, len); + buf[len] = '\0'; + } + + return buf; +} + +__attribute__((used)) +char *strndup(const char *s, size_t n) +{ + int len = strnlen(s, n); + char *buf = malloc(len + 1); + + if (buf) { + + strncpy(buf, s, len); + buf[len] = '\0'; + } + + return buf; +} diff --git a/bsp/AE210P/libc/string/strlen.c b/bsp/AE210P/libc/string/strlen.c new file mode 100644 index 0000000000..02e919d867 --- /dev/null +++ b/bsp/AE210P/libc/string/strlen.c @@ -0,0 +1,23 @@ +#include <string.h> + +__attribute__((used)) +size_t strlen(const char *s) +{ + size_t n = 0; + + while (*s++) + n++; + + return n; +} + +__attribute__((used)) +size_t strnlen(const char *s, size_t maxlen) +{ + size_t n = 0; + + while (*s++ && maxlen--) + n++; + + return n; +} diff --git a/bsp/AE210P/libc/string/strstr.c b/bsp/AE210P/libc/string/strstr.c new file mode 100644 index 0000000000..b3b8782836 --- /dev/null +++ b/bsp/AE210P/libc/string/strstr.c @@ -0,0 +1,45 @@ +#include <string.h> + +/* FIXME: LICENSE */ +__attribute__((used)) +char *strstr(const char *haystack, const char *needle) +{ + const char *start_s1 = (void *)0; + const char *in_s2 = (void *)0; + + for (; *haystack != '\0'; haystack++) { + + if (!start_s1) { + + /* first char of match */ + if (*haystack == *needle) { + + /* remember start of matching substring in haystack */ + start_s1 = haystack; + in_s2 = needle + 1; + /* done already? */ + if (*in_s2 == '\0') + return (char*)start_s1; + } + /* continued mis-match + else + nothing ; */ + } + else { + + /* continued match */ + if (*haystack == *in_s2) { + + in_s2++; + /* done */ + if (*in_s2 == '\0') + return (char*)start_s1; + } + else + /* first char of mis-match */ + start_s1 = (void *)0; + } + } + + return (void *)0; +} diff --git a/bsp/AE210P/libc/string/strtoul.c b/bsp/AE210P/libc/string/strtoul.c new file mode 100644 index 0000000000..91432026e1 --- /dev/null +++ b/bsp/AE210P/libc/string/strtoul.c @@ -0,0 +1,82 @@ +#include <string.h> +#include <ctype.h> + +/* FIXME: LICENSE */ +__attribute__((used)) +unsigned long int strtoul(const char *nptr, char **endptr, int base) +{ + const char *s; + unsigned long acc, cutoff; + int c; + int neg, any, cutlim; + + s = nptr; + do + c = *s++; + while (isspace(c)); + + if (c == '-') { + + neg = 1; + c = *s++; + } + else { + neg = 0; + if (c == '+') + c = *s++; + } + + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { + + c = s[1]; + s += 2; + base = 16; + } + + if (base == 0) + base = c == '0' ? 8 : 10; + +#ifndef ULONG_MAX +#define ULONG_MAX (unsigned long) -1 +#endif + + cutoff = ULONG_MAX / (unsigned long)base; + cutlim = ULONG_MAX % (unsigned long)base; + + for (acc = 0, any = 0;; c = *s++) { + + if (isdigit(c)) + c -= '0'; + + else if (isalpha(c)) + + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + + if (c >= base) + break; + + if (any < 0) + continue; + + // FIXME + if (acc > cutoff || (acc == cutoff && c > cutlim)) { + + any = -1; + acc = ULONG_MAX; + } + else { + any = 1; + acc *= (unsigned long)base; + acc += c; + } + } + if (neg && any > 0) + acc = -acc; + + if (endptr != 0) + *endptr = (char *)(any ? s - 1 : nptr); + + return acc; +} diff --git a/bsp/AE210P/libc/string/strupr.c b/bsp/AE210P/libc/string/strupr.c new file mode 100644 index 0000000000..f56c7a9f50 --- /dev/null +++ b/bsp/AE210P/libc/string/strupr.c @@ -0,0 +1,16 @@ +#include <string.h> + +__attribute__((used)) +char *strupr(char *str) +{ + char *str_iter = str; + + while (*str_iter != 0) + { + if ((*str_iter >= 'a') && (*str_iter <= 'z')) + *str_iter -= 0x20; + ++str_iter; + } + + return str; +} diff --git a/bsp/AE210P/libc/string/wchar.c b/bsp/AE210P/libc/string/wchar.c new file mode 100644 index 0000000000..7b0a4219dd --- /dev/null +++ b/bsp/AE210P/libc/string/wchar.c @@ -0,0 +1,147 @@ +#include <string.h> + +__attribute__((used)) +wchar_t *wcscat(wchar_t *str_dst, const wchar_t *str_src) +{ + wchar_t *dst_iter = str_dst; + int i = 0; + + while (*dst_iter != 0) + ++dst_iter; + + while (str_src[i] != 0) + { + dst_iter[i] = str_src[i]; + ++i; + } + + dst_iter[i] = 0; + + return str_dst; +} + +__attribute__((used)) +int wcscmp(const wchar_t *string1, const wchar_t *string2) +{ + int i = 0; + register wchar_t c1, c2; + + while (1) + { + c1 = string1[i]; + c2 = string2[i]; + + if (c1 < c2) + { + return -1; + } + else if (c1 > c2) + { + return 1; + } + + if ((c1 == 0) || (c2 == 0)) + break; + + ++i; + } + + return 0; +} + +__attribute__((used)) +int wcsncmp(const wchar_t *string1, const wchar_t *string2, int count) +{ + int i = 0; + + while (i < count) + { + if (string1[i] < string2[i]) + { + return -1; + } + else if (string1[i] > string2[i]) + { + return 1; + } + + if ((string1[i] == 0) || (string2[i] == 0)) + break; + ++i; + } + + return 0; +} + +__attribute__((used)) +wchar_t *wcscpy(wchar_t *str_dst, const wchar_t *str_src) +{ + int i = 0; + + while (str_src[i] != 0) + { + str_dst[i] = str_src[i]; + ++i; + } + + str_dst[i] = 0; + + return str_dst; +} + +__attribute__((used)) +wchar_t *wcsncpy(wchar_t *str_dst, const wchar_t *str_src, int count) +{ + int i = 0; + + while ((str_src[i] != 0) && (i < count)) + { + str_dst[i] = str_src[i]; + ++i; + } + + str_dst[i] = 0; + + return str_dst; +} + +__attribute__((used)) +int wcslen(const wchar_t *str) +{ + int i = 0; + + while (str[i] != 0) + ++i; + + return i; +} + +__attribute__((used)) +wchar_t *wcsupr(wchar_t *str) +{ + wchar_t *str_iter = str; + + while (*str_iter != 0) + { + if ((*str_iter >= (wchar_t)'a') && (*str_iter <= (wchar_t)'z')) + *str_iter -= 0x0020; + ++str_iter; + } + + return str; +} + +__attribute__((used)) +wchar_t *wcslwr(wchar_t *str) +{ + wchar_t *str_iter = str; + + while (*str_iter != 0) + { + if ((*str_iter <= (wchar_t)'Z') && (*str_iter >= (wchar_t)'A')) + *str_iter += 0x0020; + ++str_iter; + } + + return str; +} |
