diff options
| author | Anup Patel <anup.patel@wdc.com> | 2019-01-18 10:28:58 +0530 |
|---|---|---|
| committer | Anup Patel <anup@brainfault.org> | 2019-01-18 10:47:30 +0530 |
| commit | ebfe23125666a11fd3dc14b85f5ca58b7f40276b (patch) | |
| tree | eacf671042d394bcb6e615cc9c7278c1349153b3 /platform/common/libc/string.c | |
| parent | e0686ca844f6c7372edd353cffe08ddee5dcf5c9 (diff) | |
| download | opensbi-ebfe23125666a11fd3dc14b85f5ca58b7f40276b.tar.gz opensbi-ebfe23125666a11fd3dc14b85f5ca58b7f40276b.tar.bz2 opensbi-ebfe23125666a11fd3dc14b85f5ca58b7f40276b.zip | |
platform: Fix compile error caused by standard includes
Avoid using standard includes namely stdint.h, string.h, stdlib.h, etc.
All standard include except stddef.h give compilation error due
to differences in RISC-V toolchain configuration. Typically, the
compilation error is related to "gnu-stubs-lp64.h".
This patch fixes compile error caused by standard includes by
providing substitutes of definetions provided by standard includes
wherever required.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'platform/common/libc/string.c')
| -rw-r--r-- | platform/common/libc/string.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/platform/common/libc/string.c b/platform/common/libc/string.c index cb467a6b..9c094458 100644 --- a/platform/common/libc/string.c +++ b/platform/common/libc/string.c @@ -12,12 +12,13 @@ * bugs as well. Use any optimized routines from newlib or glibc if required. */ -#include <string.h> +#include <plat/string.h> int strcmp(const char *a, const char *b) { /* search first diff or end of string */ for (; *a == *b && *a != '\0'; a++, b++); + return *a - *b; } @@ -46,7 +47,7 @@ size_t strnlen(const char *str, size_t count) return ret; } -char * strcpy(char * dest,const char *src) +char *strcpy(char *dest, const char *src) { char *ret = dest; @@ -57,7 +58,7 @@ char * strcpy(char * dest,const char *src) return ret; } -char * strncpy(char * dest,const char *src,size_t count) +char *strncpy(char *dest, const char *src, size_t count) { char *ret = dest; @@ -68,7 +69,7 @@ char * strncpy(char * dest,const char *src,size_t count) return ret; } -char * strchr(const char * s, int c) +char *strchr(const char *s, int c) { while(*s != '\0' && *s != (char)c) s++; @@ -79,7 +80,7 @@ char * strchr(const char * s, int c) return (char *)s; } -char * strrchr(const char * s, int c) +char *strrchr(const char *s, int c) { const char *last = s + strlen(s); @@ -91,7 +92,7 @@ char * strrchr(const char * s, int c) else return (char *)last; } -void * memset(void * s,int c,size_t count) +void *memset(void *s, int c, size_t count) { char *temp = s; @@ -103,7 +104,7 @@ void * memset(void * s,int c,size_t count) return s; } -void * memcpy(void *dest, const void *src, size_t count) +void *memcpy(void *dest, const void *src, size_t count) { char *temp1 = dest; const char *temp2 = src; @@ -116,7 +117,7 @@ void * memcpy(void *dest, const void *src, size_t count) return dest; } -void * memmove(void * dest,const void *src,size_t count) +void *memmove(void *dest, const void *src, size_t count) { char *temp1 = (char *)dest; const char *temp2 = (char *)src; @@ -138,13 +139,15 @@ void * memmove(void * dest,const void *src,size_t count) count--; } } + return dest; } -int memcmp(const void * s1,const void * s2,size_t count) +int memcmp(const void *s1, const void *s2, size_t count) { const char *temp1 = s1; const char *temp2 = s2; + for (; count > 0 && (*temp1 == *temp2); count--) { temp1++; temp2++; @@ -166,5 +169,6 @@ void *memchr(const void *s, int c, size_t count) } count--; } + return NULL; } |
