aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-24 16:09:04 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-24 16:09:04 +0100
commitf2c07854463763ed82e00857ae6d9bcbc924e42c (patch)
treeddeac108511835400cfba6525f7e9ca865afb1e4 /src/common
parent7e908dabaaf6c67ef5000406a0bb3a6a29beca01 (diff)
downloadkogata-f2c07854463763ed82e00857ae6d9bcbc924e42c.tar.gz
kogata-f2c07854463763ed82e00857ae6d9bcbc924e42c.zip
Make way for ISO 9660 driver.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/include/string.h1
-rw-r--r--src/common/libc/string.c14
2 files changed, 14 insertions, 1 deletions
diff --git a/src/common/include/string.h b/src/common/include/string.h
index 686382d..e655f2c 100644
--- a/src/common/include/string.h
+++ b/src/common/include/string.h
@@ -18,5 +18,6 @@ int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
char *strdup(const char* str);
+char *strndup(const char* str, size_t count);
/* vim: set ts=4 sw=4 tw=0 noet :*/
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 :*/