aboutsummaryrefslogtreecommitdiffstats
path: root/test.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-28 13:45:34 +0200
committerMattias Andrée <maandree@kth.se>2018-08-28 13:45:34 +0200
commitf27708ce206f97896bcf001d00d126f91ff7a5c8 (patch)
tree622f2abc1f2d8535474c4f36709bb6dd40be39c1 /test.c
parentSimplify en* functions, and handle argv0 == NULL correct (diff)
downloadlibsimple-f27708ce206f97896bcf001d00d126f91ff7a5c8.tar.gz
libsimple-f27708ce206f97896bcf001d00d126f91ff7a5c8.tar.bz2
libsimple-f27708ce206f97896bcf001d00d126f91ff7a5c8.tar.xz
Make it possible to force all memory allocation functions to fail in tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'test.c')
-rw-r--r--test.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/test.c b/test.c
index 05d74d4..ad5a4bc 100644
--- a/test.c
+++ b/test.c
@@ -3,6 +3,9 @@
#include "test.h"
#include <malloc.h>
+#undef strndup
+#undef memdup
+
size_t alloc_fail_in = 0;
@@ -185,6 +188,28 @@ pvalloc(size_t size)
}
+char *
+strdup(const char *s)
+{
+ char *r = malloc(strlen(s) + 1);
+ return r ? strcpy(r, s) : r;
+}
+
+
+char *
+strndup(const char *s, size_t size)
+{
+ return libsimple_strndup(s, size);
+}
+
+
+void *
+memdup(const void *s, size_t size)
+{
+ return libsimple_memdup(s, size);
+}
+
+
void
free(void *ptr)
{