diff --git a/configure.ac b/configure.ac index 5f0277b..f0e627b 100644 --- a/configure.ac +++ b/configure.ac @@ -319,6 +319,9 @@ elif test -n "$NEEDS_SOCKET" ; then LIBS="$LIBS -lsocket" elif test -n "$NEEDS_NSL" ; then LIBS="$LIBS -lnsl" +else + # Needed for MinGW / Windows + AC_SEARCH_LIBS(inet_pton, ws2_32) fi # Check for clock_gettime() used for performance measurement @@ -365,7 +368,7 @@ AC_SUBST(PSL_TESTFILE) # check for alloca / alloca.h AC_FUNC_ALLOCA -AC_CHECK_FUNCS([strndup clock_gettime fmemopen]) +AC_CHECK_FUNCS([strndup clock_gettime fmemopen nl_langinfo]) # 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 cbac592..cce5da6 100644 --- a/src/psl.c +++ b/src/psl.c @@ -102,30 +102,12 @@ # include #endif -#include - -#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; - size_t s_len = strlen(s); - - if (s_len > n) - n = s_len; - - dst = malloc(n + 1); - - if (dst) { - memcpy(dst, s, n); - dst[n] = 0; - } - - return dst; -} +#ifndef WINICONV_CONST +# define WINICONV_CONST #endif +#include + /** * SECTION:libpsl * @short_description: Public Suffix List library functions @@ -1812,8 +1794,13 @@ out: do { /* find out local charset encoding */ if (!encoding) { +#ifdef HAVE_NL_LANGINFO encoding = nl_langinfo(CODESET); - +#elif defined _WIN32 + static char buf[16]; + snprintf(buf, sizeof(buf), "CP%u", GetACP()); + encoding = buf; +#endif if (!encoding || !*encoding) encoding = "ASCII"; } @@ -1831,7 +1818,7 @@ out: if (!dst) { ret = PSL_ERR_NO_MEM; } - else if (iconv(cd, &tmp, &tmp_len, &dst_tmp, &dst_len_tmp) != (size_t)-1 + else if (iconv(cd, (WINICONV_CONST char **)&tmp, &tmp_len, &dst_tmp, &dst_len_tmp) != (size_t)-1 && iconv(cd, NULL, NULL, &dst_tmp, &dst_len_tmp) != (size_t)-1) { /* start size for u8_tolower internal memory allocation.