diff --git a/configure.ac b/configure.ac index ee3d272..ed08540 100644 --- a/configure.ac +++ b/configure.ac @@ -231,6 +231,7 @@ AC_SUBST(PSL_TESTFILE) # check for alloca / alloca.h AC_FUNC_ALLOCA +AC_CHECK_FUNCS([strndup]) # Override the template file name of the generated .pc file, so that there # is no need to rename the template file when the API version changes. diff --git a/src/psl.c b/src/psl.c index d0dbb10..4bc6e53 100644 --- a/src/psl.c +++ b/src/psl.c @@ -93,6 +93,22 @@ /* number of elements within an array */ #define countof(a) (sizeof(a)/sizeof(*(a))) +#ifndef HAVE_STRNDUP +// I found no strndup on my old SUSE 7.3 test system (gcc 2.95) + +static char *strndup(const char *s, size_t n) +{ + char *dst = malloc(n + 1); + + if (dst) { + memcpy(dst, s, n); + dst[n] = 0; + } + + return dst; +} +#endif + /** * SECTION:libpsl * @short_description: Public Suffix List library functions