aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPHO <pho@cielonegro.org>2015-01-26 13:02:15 +0900
committerMax Kellermann <max@duempel.org>2015-01-26 20:39:49 +0100
commit023b9c1e7e6792de4da0b867b6bb5d425928bd5b (patch)
tree5f6b62d9ac30a7262763ca654a1017ba6233a19a
parent4c616626440beaedd125a788faecf06a3ebe85af (diff)
downloadmpd-023b9c1e7e6792de4da0b867b6bb5d425928bd5b.tar.gz
mpd-023b9c1e7e6792de4da0b867b6bb5d425928bd5b.tar.xz
mpd-023b9c1e7e6792de4da0b867b6bb5d425928bd5b.zip
Test the existence of strndup(3) before using it.
This can eliminate the ad-hoc "#ifdef WIN32" and can also support other platforms lacking it as well (including Darwin 9).
-rw-r--r--NEWS1
-rw-r--r--configure.ac1
-rw-r--r--src/util/Alloc.cxx11
3 files changed, 8 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 82ba78548..02a18fd42 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
ver 0.19.9 (not yet released)
* fix build failure with uClibc
+* fix build failure on non-POSIX operating systems
ver 0.19.8 (2015/01/14)
* input
diff --git a/configure.ac b/configure.ac
index d36afffa4..199ff9896 100644
--- a/configure.ac
+++ b/configure.ac
@@ -206,6 +206,7 @@ if test x$host_is_linux = xyes; then
fi
AC_CHECK_FUNCS(getpwnam_r getpwuid_r)
+AC_CHECK_FUNCS(strndup)
if test x$host_is_linux = xyes; then
MPD_OPTIONAL_FUNC(eventfd, eventfd, USE_EVENTFD)
diff --git a/src/util/Alloc.cxx b/src/util/Alloc.cxx
index ec3579470..006e09701 100644
--- a/src/util/Alloc.cxx
+++ b/src/util/Alloc.cxx
@@ -17,6 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
#include "Alloc.hxx"
#include <stdlib.h>
@@ -62,14 +63,14 @@ xstrdup(const char *s)
char *
xstrndup(const char *s, size_t n)
{
-#ifdef WIN32
- char *p = (char *)xalloc(n + 1);
- memcpy(p, s, n);
- p[n] = 0;
-#else
+#ifdef HAVE_STRNDUP
char *p = strndup(s, n);
if (gcc_unlikely(p == nullptr))
oom();
+#else
+ char *p = (char *)xalloc(n + 1);
+ memcpy(p, s, n);
+ p[n] = 0;
#endif
return p;