You need to sign in or sign up before continuing.
Commit 023b9c1e authored by PHO's avatar PHO Committed by Max Kellermann

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).
parent 4c616626
ver 0.19.9 (not yet released) ver 0.19.9 (not yet released)
* fix build failure with uClibc * fix build failure with uClibc
* fix build failure on non-POSIX operating systems
ver 0.19.8 (2015/01/14) ver 0.19.8 (2015/01/14)
* input * input
......
...@@ -206,6 +206,7 @@ if test x$host_is_linux = xyes; then ...@@ -206,6 +206,7 @@ if test x$host_is_linux = xyes; then
fi fi
AC_CHECK_FUNCS(getpwnam_r getpwuid_r) AC_CHECK_FUNCS(getpwnam_r getpwuid_r)
AC_CHECK_FUNCS(strndup)
if test x$host_is_linux = xyes; then if test x$host_is_linux = xyes; then
MPD_OPTIONAL_FUNC(eventfd, eventfd, USE_EVENTFD) MPD_OPTIONAL_FUNC(eventfd, eventfd, USE_EVENTFD)
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "config.h"
#include "Alloc.hxx" #include "Alloc.hxx"
#include <stdlib.h> #include <stdlib.h>
...@@ -62,14 +63,14 @@ xstrdup(const char *s) ...@@ -62,14 +63,14 @@ xstrdup(const char *s)
char * char *
xstrndup(const char *s, size_t n) xstrndup(const char *s, size_t n)
{ {
#ifdef WIN32 #ifdef HAVE_STRNDUP
char *p = (char *)xalloc(n + 1);
memcpy(p, s, n);
p[n] = 0;
#else
char *p = strndup(s, n); char *p = strndup(s, n);
if (gcc_unlikely(p == nullptr)) if (gcc_unlikely(p == nullptr))
oom(); oom();
#else
char *p = (char *)xalloc(n + 1);
memcpy(p, s, n);
p[n] = 0;
#endif #endif
return p; return p;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment