From 023b9c1e7e6792de4da0b867b6bb5d425928bd5b Mon Sep 17 00:00:00 2001
From: PHO <pho@cielonegro.org>
Date: Mon, 26 Jan 2015 13:02:15 +0900
Subject: 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).
---
 src/util/Alloc.cxx | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

(limited to 'src/util')

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;
-- 
cgit v1.2.3