summaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/utils.c b/src/utils.c
index 1aea66f..9698825 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -6,21 +6,18 @@
char *strndup(const char *s, size_t n)
{
- /* this assumes s is NUL terminated - if not,
- * some silly value will be returned */
- size_t len = strlen(s);
+ size_t len = 0;
char *res;
- /* limit to n */
- if (len > n || n == 0)
- len = n;
+ while (len < n && s[len] != '\0')
+ len++;
- res = (char *) malloc(len + 1);
+ res = malloc(len + 1);
if (res == NULL)
return NULL;
res[len] = '\0';
- return (char *) memcpy(res, s, len);
+ return memcpy(res, s, len);
}
/**