aboutsummaryrefslogtreecommitdiffstats
path: root/strndup.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-25 23:01:22 +0200
committerMattias Andrée <maandree@kth.se>2018-08-25 23:01:22 +0200
commit6912e596b839e658aa83538731a91c726e5973f5 (patch)
treeeca9ef0baa1454172d1a40775ba115629de63eb3 /strndup.c
parentAdd more tests (diff)
downloadlibsimple-6912e596b839e658aa83538731a91c726e5973f5.tar.gz
libsimple-6912e596b839e658aa83538731a91c726e5973f5.tar.bz2
libsimple-6912e596b839e658aa83538731a91c726e5973f5.tar.xz
Some fixes and more tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--strndup.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/strndup.c b/strndup.c
index df2a69d..faa3bb1 100644
--- a/strndup.c
+++ b/strndup.c
@@ -4,7 +4,7 @@
char *
-libsimple_strndup(const char *s, size_t n) /* FIXME */
+libsimple_strndup(const char *s, size_t n)
{
char *ret;
size_t m = strlen(s);
@@ -25,29 +25,29 @@ libsimple_strndup(const char *s, size_t n) /* FIXME */
#include "test.h"
int
-main(void) /* TODO valgrind */
+main(void)
{
const char *s = "test";
void *p;
- p = libsimple_memdup(s, 5);
+ p = libsimple_strndup(s, 5);
assert(p && p != s);
assert(!strcmpnul(p, "test"));
memset(p, 0, 5);
assert(!strcmpnul(s, "test"));
free(p);
- p = libsimple_memdup(s, 3);
+ p = libsimple_strndup(s, 3);
assert(p && p != s);
assert(!strcmpnul(p, "tes"));
- memset(p, 0, 5);
+ memset(p, 0, 4);
assert(!strcmpnul(s, "test"));
free(p);
- p = libsimple_memdup(s, 0);
+ p = libsimple_strndup(s, 0);
assert(p && p != s);
assert(!strcmpnul(p, ""));
- memset(p, 0, 5);
+ memset(p, 0, 1);
assert(!strcmpnul(s, "test"));
free(p);