summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-07-11 14:39:20 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-07-11 14:39:20 +0000
commit9cbc33f9eb0cab52d50dbc0f571cc88cc665c146 (patch)
treeb3740d9cf656d69b8f7988bb4ce5f90e7b7c1e91 /test
parent968235f0c8cd83601275d0d252cf5eb04844db91 (diff)
downloadlibhubbub-9cbc33f9eb0cab52d50dbc0f571cc88cc665c146.tar.gz
libhubbub-9cbc33f9eb0cab52d50dbc0f571cc88cc665c146.tar.bz2
Provide an strndup implementation for those platforms that don't have it (yay Mac OS)
svn path=/trunk/hubbub/; revision=4600
Diffstat (limited to 'test')
-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