diff --git a/configure.ac b/configure.ac index 330acc8..8e7b0a8 100644 --- a/configure.ac +++ b/configure.ac @@ -356,7 +356,9 @@ AC_ARG_WITH(psl-testfile, PSL_TESTFILE="\$(top_srcdir)/list/tests/tests.txt") AC_SUBST(PSL_TESTFILE) -AC_CHECK_FUNCS([strndup clock_gettime fmemopen nl_langinfo]) +AC_CHECK_FUNCS([strdup strndup clock_gettime fmemopen nl_langinfo]) +AC_CHECK_DECLS([strdup]) +AC_CHECK_DECLS([localtime_r]) # check for dirent.h AC_HEADER_DIRENT diff --git a/meson.build b/meson.build index a072988..93eb77d 100644 --- a/meson.build +++ b/meson.build @@ -94,7 +94,7 @@ config.set('ENABLE_BUILTIN', enable_builtin) config.set('HAVE_UNISTD_H', cc.check_header('unistd.h')) config.set('HAVE_STDINT_H', cc.check_header('stdint.h')) config.set('HAVE_DIRENT_H', cc.check_header('dirent.h')) -config.set('HAVE_STRNDUP', cc.has_function('strndup')) +config.set('HAVE_STRDUP', cc.has_function('strdup')) config.set('HAVE_CLOCK_GETTIME', cc.has_function('clock_gettime')) config.set('HAVE_FMEMOPEN', cc.has_function('fmemopen')) config.set('HAVE_NL_LANGINFO', cc.has_function('nl_langinfo')) diff --git a/src/psl.c b/src/psl.c index fa6bfd4..8863ee9 100644 --- a/src/psl.c +++ b/src/psl.c @@ -320,6 +320,23 @@ static int suffix_init(psl_entry_t *suffix, const char *rule, size_t length) return 0; } +#ifndef HAVE_STRDUP +static char *strdup(const char *s) +{ + char *p = malloc(strlen(s) + 1); + if (!p) + return NULL; + return strcpy(p, s); +} +#elif !HAVE_DECL_STRDUP +/* + * On Linux with + * CC=gcc CFLAGS="-Wall -Wextra -Wpedantic -std=c89" ./configure + * strdup isn't declared (warning: implicit declaration of function 'strdup'). + */ +char *strdup(const char *); +#endif + #if !defined(WITH_LIBIDN) && !defined(WITH_LIBIDN2) && !defined(WITH_LIBICU) /* * When configured without runtime IDNA support (./configure --disable-runtime), we need a pure ASCII @@ -675,9 +692,9 @@ static int psl_idna_toASCII(psl_idna_t *idna, const char *utf8, char **ascii) { int ret = -1; +#if defined(WITH_LIBICU) (void) idna; -#if defined(WITH_LIBICU) /* IDNA2008 UTS#46 punycode conversion */ if (idna) { char lookupname_buf[128] = "", *lookupname = lookupname_buf; @@ -737,6 +754,8 @@ static int psl_idna_toASCII(psl_idna_t *idna, const char *utf8, char **ascii) #if IDN2_VERSION_NUMBER >= 0x00140000 int rc; + (void) idna; + /* IDN2_TRANSITIONAL automatically converts to lowercase * IDN2_NFC_INPUT converts to NFC before toASCII conversion * Since IDN2_TRANSITIONAL implicitly does NFC conversion, we don't need @@ -769,6 +788,8 @@ static int psl_idna_toASCII(psl_idna_t *idna, const char *utf8, char **ascii) #elif defined(WITH_LIBIDN) int rc; + (void) idna; + if (!utf8_is_valid(utf8)) { /* fprintf(stderr, "Invalid UTF-8 sequence not converted: '%s'\n", utf8); */ return -1; @@ -783,6 +804,8 @@ static int psl_idna_toASCII(psl_idna_t *idna, const char *utf8, char **ascii) #else char lookupname[128]; + (void) idna; + if (domain_to_punycode(utf8, lookupname, sizeof(lookupname)) == 0) { if (ascii) if ((*ascii = strdup(lookupname))) @@ -835,7 +858,7 @@ static int is_public_suffix(const psl_ctx_t *psl, const char *domain, int type) for (p = domain; *p; p++) { if (*p == '.') { - if (suffix.nlabels == 255) // weird input, avoid 8bit overflow + if (suffix.nlabels == 255) /* weird input, avoid 8bit overflow */ return 0; suffix.nlabels++; } diff --git a/tools/psl.c b/tools/psl.c index 527d780..564a2e5 100644 --- a/tools/psl.c +++ b/tools/psl.c @@ -41,10 +41,15 @@ // Windows does not have localtime_r but has localtime_s, which is more or less // the same except that the arguments are reversed -# define LOCALTIME_R_SUCCESSFUL(t_sec,t_now) \ +# define LOCALTIME_R_SUCCESSFUL(t_sec, t_now) \ (localtime_s(t_now, t_sec) == 0) #else -# define LOCALTIME_R_SUCCESSFUL(t_sec,t_now) \ +# include +# if ! HAVE_DECL_LOCALTIME_R +struct tm *localtime_r(const time_t *, struct tm *); +#endif + +# define LOCALTIME_R_SUCCESSFUL(t_sec, t_now) \ (localtime_r(t_sec, t_now) != NULL) #endif