Skip to content

Commit

Permalink
Add strdup() in case it isn't available
Browse files Browse the repository at this point in the history
  • Loading branch information
rockdaboot committed Feb 11, 2024
1 parent ebf63cb commit aea83d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ 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])

# check for dirent.h
AC_HEADER_DIRENT
Expand Down
17 changes: 17 additions & 0 deletions src/psl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aea83d8

Please sign in to comment.