diff options
author | Mattias Andrée <maandree@kth.se> | 2018-08-28 13:45:34 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2018-08-28 13:45:34 +0200 |
commit | f27708ce206f97896bcf001d00d126f91ff7a5c8 (patch) | |
tree | 622f2abc1f2d8535474c4f36709bb6dd40be39c1 /test.c | |
parent | Simplify en* functions, and handle argv0 == NULL correct (diff) | |
download | libsimple-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 '')
-rw-r--r-- | test.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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) { |