From 9cbc33f9eb0cab52d50dbc0f571cc88cc665c146 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Fri, 11 Jul 2008 14:39:20 +0000 Subject: Provide an strndup implementation for those platforms that don't have it (yay Mac OS) svn path=/trunk/hubbub/; revision=4600 --- test/testutils.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/testutils.h') 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 #include #include +#include #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 -- cgit v1.2.3