aboutsummaryrefslogtreecommitdiff
path: root/src/common/string.c
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-12 19:57:43 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-12 19:57:43 +0100
commit7284663b72c6a9c42579a6f7690bf6085c604bda (patch)
tree75b964d074a7116f1d1e129cce7bcc2278acaaca /src/common/string.c
parent493b5a2cf072c1f183d4724c9c0cc7b63d4771ae (diff)
downloadkogata-7284663b72c6a9c42579a6f7690bf6085c604bda.tar.gz
kogata-7284663b72c6a9c42579a6f7690bf6085c604bda.zip
Begin ajusting vfs.c
Diffstat (limited to 'src/common/string.c')
-rw-r--r--src/common/string.c20
1 files changed, 19 insertions, 1 deletions
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;