summaryrefslogtreecommitdiff
path: root/test/testutils.h
diff options
context:
space:
mode:
Diffstat (limited to 'test/testutils.h')
-rw-r--r--test/testutils.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/testutils.h b/test/testutils.h
index 68657f8..5a912e1 100644
--- a/test/testutils.h
+++ b/test/testutils.h
@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#ifndef UNUSED
#define UNUSED(x) ((x) = (x))
@@ -120,4 +121,28 @@ size_t parse_filesize(const char *filename)
}
+#ifndef strndup
+char *my_strndup(const char *s, size_t n);
+
+char *my_strndup(const char *s, size_t n)
+{
+ size_t len;
+ char *s2;
+
+ for (len = 0; len != n && s[len]; len++)
+ ;
+
+ s2 = malloc(len + 1);
+ if (!s2)
+ return NULL;
+
+ memcpy(s2, s, len);
+ s2[len] = '\0';
+
+ return s2;
+}
+
+#define strndup my_strndup
+#endif
+
#endif