From: John Mark Bell Date: Wed, 29 Dec 2010 18:06:04 +0000 (-0000) Subject: Use built-in strndup if the platform we're targetting doesn't have one X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=5533143958b16ed87026cdf533fc4d544b2d712f;p=libsvgtiny.git Use built-in strndup if the platform we're targetting doesn't have one svn path=/trunk/libsvgtiny/; revision=11140 --- 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 */ -#define _GNU_SOURCE /* for strndup */ #include #include #include @@ -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 */ -#define _GNU_SOURCE /* for strndup */ #include #include #include 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);