aboutsummaryrefslogtreecommitdiff
path: root/src/common/libc
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/libc')
-rw-r--r--src/common/libc/string.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/common/libc/string.c b/src/common/libc/string.c
index dfc93e6..e5f7a53 100644
--- a/src/common/libc/string.c
+++ b/src/common/libc/string.c
@@ -114,7 +114,7 @@ void *memset(void *dest, int val, size_t count) {
}
char *strdup(const char* str) {
- int len = strlen(str) + 1;
+ size_t len = strlen(str) + 1;
char* ret = (char*)malloc(len);
if (ret == 0) return 0;
@@ -123,4 +123,16 @@ char *strdup(const char* str) {
return ret;
}
+char *strndup(const char* str, size_t count) {
+ size_t len = strlen(str);
+ if (count < len) len = count;
+
+ char* ret = (char*)malloc(len + 1);
+ if (ret == 0) return 0;
+
+ memcpy(ret, str, len);
+ ret[len] = 0;
+ return ret;
+}
+
/* vim: set ts=4 sw=4 tw=0 noet :*/