add strndup() compatibility code

This commit is contained in:
Tim Rühsen 2015-01-23 15:05:02 +01:00
parent 768790eab7
commit 910c4b37b6
2 changed files with 17 additions and 0 deletions

View File

@ -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.

View File

@ -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