summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/string.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/lib/string.c b/src/lib/string.c
index d50435f..8ebf64c 100644
--- a/src/lib/string.c
+++ b/src/lib/string.c
@@ -20,7 +20,7 @@ size_t strnlen(const char *s, size_t maxlen)
{
size_t c = 0;
- while (c <= maxlen && s[c])
+ while (c < maxlen && s[c])
c++;
return c;
@@ -37,6 +37,21 @@ char *strcpy(char *restrict dst, const char *restrict src)
return dst;
}
+char *strncpy(char *restrict dst, const char *restrict src, size_t dsize)
+{
+ size_t pos = 0;
+
+ for(pos = 0; pos < dsize && src[pos] != '\0'; pos++)
+ dst[pos] = src[pos];
+
+ while (pos < dsize) {
+ dst[pos] = '\0';
+ pos++;
+ }
+
+ return dst;
+}
+
int strncmp(const char *s1, const char *s2, size_t n)
{
int i = 0;