aboutsummaryrefslogtreecommitdiff
path: root/src/common/string.c
diff options
context:
space:
mode:
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;