From 7284663b72c6a9c42579a6f7690bf6085c604bda Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 12 Feb 2015 19:57:43 +0100 Subject: Begin ajusting vfs.c --- src/common/string.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/common/string.c') diff --git a/src/common/string.c b/src/common/string.c index dc25aee..b50356a 100644 --- a/src/common/string.c +++ b/src/common/string.c @@ -26,7 +26,15 @@ char *strrchr(const char *str, char c) { char *strcpy(char *dest, const char *src) { memcpy(dest, src, strlen(src) + 1); - return (char*)src; + return (char*)dest; +} + +char *strncpy(char *dest, const char *src, size_t n) { + size_t x = strlen(src + 1); + if (n < x) x = n; + memcpy(dest, src, x); + if (n > x) memset(dest + n, 0, n - x); + return (char*)dest; } char *strcat(char *dest, const char *src) { @@ -49,6 +57,16 @@ int strcmp(const char *s1, const char *s2) { return (*(unsigned char*)s1 - *(unsigned char*)s2); } +int strcmp(const char *s1, const char *s2, size_t n) { + size_t i = 0; + while ((*s1) && (*s1 == *s2) && i != n) { + s1++; + s2++; + i++; + } + return (*(unsigned char*)s1 - *(unsigned char*)s2); +} + void *memcpy(void *vd, const void *vs, size_t count) { uint8_t *dest = (uint8_t*)vd, *src = (uint8_t*)vs; size_t f = count % 4, n = count / 4, i; -- cgit v1.2.3