summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2010-12-29 18:06:04 (GMT)
committer John Mark Bell <jmb@netsurf-browser.org>2010-12-29 18:06:04 (GMT)
commit5533143958b16ed87026cdf533fc4d544b2d712f (patch)
tree3921d20a69b2dcb4802951acbb037c5448868979
parent9730f6727c1ceac012441f5ffb4bce3ab0759526 (diff)
downloadlibsvgtiny-5533143958b16ed87026cdf533fc4d544b2d712f.tar.gz
libsvgtiny-5533143958b16ed87026cdf533fc4d544b2d712f.tar.bz2
Use built-in strndup if the platform we're targetting doesn't have one
svn path=/trunk/libsvgtiny/; revision=11140
-rw-r--r--src/svgtiny.c21
-rw-r--r--src/svgtiny_gradient.c1
-rw-r--r--src/svgtiny_internal.h6
3 files changed, 26 insertions, 2 deletions
diff --git a/src/svgtiny.c b/src/svgtiny.c
index 5a6e988..af1db24 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -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
+
diff --git a/src/svgtiny_gradient.c b/src/svgtiny_gradient.c
index 9c6e82e..3a8db73 100644
--- a/src/svgtiny_gradient.c
+++ b/src/svgtiny_gradient.c
@@ -5,7 +5,6 @@
* Copyright 2008 James Bursa <james@semichrome.net>
*/
-#define _GNU_SOURCE /* for strndup */
#include <assert.h>
#include <math.h>
#include <string.h>
diff --git a/src/svgtiny_internal.h b/src/svgtiny_internal.h
index 3ea6e7b..13db00e 100644
--- a/src/svgtiny_internal.h
+++ b/src/svgtiny_internal.h
@@ -63,6 +63,12 @@ void svgtiny_parse_transform(char *s, float *ma, float *mb,
struct svgtiny_shape *svgtiny_add_shape(struct svgtiny_parse_state *state);
void svgtiny_transform_path(float *p, unsigned int n,
struct svgtiny_parse_state *state);
+#if defined(_GNU_SOURCE)
+#define HAVE_STRNDUP
+#else
+#undef HAVE_STRNDUP
+char *strndup(const char *s, size_t n);
+#endif
/* svgtiny_gradient.c */
void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state);