diff --git a/ChangeLog b/ChangeLog index 6a55f98..f5930b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ Version 1.6.11 ******************************************************************************* +2011-01-16 Marcelo Roberto Jimenez + + Use config.h to test for the availability of strndup() and strnlen(). + 2011-01-14 Chandra Penke - Null termination of strndup() implementation on systems missing it. diff --git a/build/inc/autoconfig.h b/build/inc/autoconfig.h index 04e10e8..363a24b 100644 --- a/build/inc/autoconfig.h +++ b/build/inc/autoconfig.h @@ -49,6 +49,12 @@ /* Define to 1 if you have the 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 header file. */ #define HAVE_SYSLOG_H 1 diff --git a/configure.ac b/configure.ac index d9858fd..03c68ba 100644 --- a/configure.ac +++ b/configure.ac @@ -497,6 +497,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]) diff --git a/upnp/src/api/UpnpString.c b/upnp/src/api/UpnpString.c index e29fbf4..f3b069e 100644 --- a/upnp/src/api/UpnpString.c +++ b/upnp/src/api/UpnpString.c @@ -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.