From d82b18c90710baf16239257272a740488fddf11c Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 22 Nov 2020 19:22:31 +0100 Subject: Added file-based HTTP server And fixed/added some other things --- libc/inc/str.h | 2 ++ libc/str.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'libc') diff --git a/libc/inc/str.h b/libc/inc/str.h index 65774e7..3156fb2 100644 --- a/libc/inc/str.h +++ b/libc/inc/str.h @@ -7,8 +7,10 @@ u32 strlen(const char *s); char *strcpy(char *dst, const char *src); +char *strncpy(char *dst, const char *src, u32 n); char *strchr(const char *s, int c); char *strcat(char *dst, const char *src); +char *strncat(char *dst, const char *src, u32 n); int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, u32 n); char *strinv(char *s); diff --git a/libc/str.c b/libc/str.c index d1ee325..7f6d782 100644 --- a/libc/str.c +++ b/libc/str.c @@ -24,6 +24,16 @@ char *strcpy(char *dst, const char *src) return dst; } +char *strncpy(char *dst, const char *src, u32 n) +{ + char *q = dst; + + while (n-- && (*dst++ = *src++)) + ; + + return q; +} + int strcmp(const char *s1, const char *s2) { const u8 *c1 = (const u8 *)s1; @@ -73,6 +83,12 @@ char *strcat(char *dst, const char *src) return dst; } +char *strncat(char *dst, const char *src, u32 n) +{ + strncpy(strchr(dst, '\0'), src, n); + return dst; +} + char *strinv(char *s) { u32 s_str = strlen(s); -- cgit v1.2.3