aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/inc/str.h2
-rw-r--r--libc/str.c16
2 files changed, 18 insertions, 0 deletions
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);