]> gitweb.michael.orlitzky.com - libsvgtiny.git/blobdiff - src/svgtiny.c
Use built-in strndup if the platform we're targetting doesn't have one
[libsvgtiny.git] / src / svgtiny.c
index 5a6e98808210e8a261e2d9bec322ce7aa7f9706c..af1db2449e1ea8d0b1d1c7ee1633dfc846d35e2c 100644 (file)
@@ -5,7 +5,6 @@
  * Copyright 2008-2009 James Bursa <james@semichrome.net>
  */
 
-#define _GNU_SOURCE  /* for strndup */
 #include <assert.h>
 #include <math.h>
 #include <setjmp.h>
@@ -1232,3 +1231,23 @@ void svgtiny_free(struct svgtiny_diagram *svg)
        free(svg);
 }
 
+#ifndef HAVE_STRNDUP
+char *strndup(const char *s, size_t n)
+{
+       size_t len;
+       char *s2;
+
+       for (len = 0; len != n && s[len]; len++)
+               continue;
+
+       s2 = malloc(len + 1);
+       if (s2 == NULL)
+               return NULL;
+
+       memcpy(s2, s, len);
+       s2[len] = '\0';
+
+       return s2;
+}
+#endif
+