Use config.h to test for the availability of strndup() and strnlen().

(cherry picked from commit 541679d6513ce0c4fc257b2b6f6708e5819c84eb)
This commit is contained in:
Marcelo Roberto Jimenez 2011-01-16 21:05:07 -02:00
parent 60c9e95637
commit 348bf19412
4 changed files with 24 additions and 9 deletions

View File

@ -244,6 +244,10 @@ Version 1.8.0
Version 1.6.11
*******************************************************************************
2011-01-16 Marcelo Roberto Jimenez <mroberto(at)users.sourceforge.net>
Use config.h to test for the availability of strndup() and strnlen().
2011-01-14 Chandra Penke <chandrapenke(at)mcntech.com>
- Null termination of strndup() implementation on systems missing it.

View File

@ -49,6 +49,12 @@
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Defines if strndup is available on your system */
#define HAVE_STRNDUP 1
/* Defines if strnlen is available on your system */
#define HAVE_STRNLEN 1
/* Define to 1 if you have the <syslog.h> header file. */
#define HAVE_SYSLOG_H 1

View File

@ -499,6 +499,10 @@ fi
#
AC_FUNC_VPRINTF
AC_FUNC_FSEEKO
AC_CHECK_FUNC(strnlen,
AC_DEFINE(HAVE_STRNLEN, 1, [Defines if strnlen is available on your system]))
AC_CHECK_FUNC(strndup,
AC_DEFINE(HAVE_STRNDUP, 1, [Defines if strndup is available on your system]))
#
# Solaris needs -lsocket -lnsl -lrt
AC_SEARCH_LIBS([bind], [socket])

View File

@ -28,20 +28,21 @@
/* Other systems have strncasecmp */
#endif
/* strndup() is a GNU extension. Other systems must fix it with elif's. */
#if defined(__GNUC__) && !defined(__APPLE__)
extern char *strndup(__const char *__string, size_t __n);
#endif /* defined(__GNUC__) && !defined(__APPLE__) */
#if defined(__GNUC__) && defined(__APPLE__)
/* strnlen() is a GNU extension. */
#if HAVE_STRNLEN
extern size_t strnlen(const char *s, size_t maxlen);
#else /* HAVE_STRNLEN */
static size_t strnlen(const char *s, size_t n)
{
const char *p = (const char *)memchr(s, 0, n);
return p ? p - s : n;
}
#endif /* defined(__GNUC__) && defined(__APPLE__) */
#endif /* HAVE_STRNLEN */
#if (defined(__GNUC__) && defined(__APPLE__)) || defined(WIN32)
/* strndup() is a GNU extension. */
#if HAVE_STRNDUP && !defined(WIN32)
extern char *strndup(__const char *__string, size_t __n);
#else /* HAVE_STRNDUP && !defined(WIN32) */
static char *strndup(const char *__string, size_t __n)
{
size_t strsize = strnlen(__string, __n);
@ -52,7 +53,7 @@
return newstr;
}
#endif /* (defined(__GNUC__) && defined(__APPLE__)) || defined(WIN32) */
#endif /* HAVE_STRNDUP && !defined(WIN32) */
/*!
* \brief Internal implementation of the class UpnpString.