aboutsummaryrefslogtreecommitdiffstats
path: root/test.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-10-27 12:12:01 +0200
committerMattias Andrée <maandree@kth.se>2018-10-27 12:12:01 +0200
commit1f7da5379b80254d6c54b4ae5b7de4686af5bba5 (patch)
tree860d07aae73f535f5bbaeb10733dac77bef45c23 /test.c
parentAdd man pages for strn[case]chr[nul] and strrn[case]chr (diff)
downloadlibsimple-1f7da5379b80254d6c54b4ae5b7de4686af5bba5.tar.gz
libsimple-1f7da5379b80254d6c54b4ae5b7de4686af5bba5.tar.bz2
libsimple-1f7da5379b80254d6c54b4ae5b7de4686af5bba5.tar.xz
Remove strndup, it is in POSIX
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--test.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/test.c b/test.c
index b954ccd..80b7ad7 100644
--- a/test.c
+++ b/test.c
@@ -216,9 +216,16 @@ strdup(const char *s)
char *
-strndup(const char *s, size_t size)
+strndup(const char *s, size_t n)
{
- return libsimple_strndup(s, size);
+ char *ret;
+ size_t m = strlen(s);
+ n = MIN(n, m);
+ if (!(ret = aligned_alloc(1, n + 1)))
+ return NULL;
+ memcpy(ret, s, n);
+ ret[n] = '\0';
+ return ret;
}