lunarmodules/lua-compat-5.3

src/compat-5.3.c:59:9: error: implicit declaration of function 'strerror_r' [-Werror=implicit-function-declaration]

Closed this issue · 0 comments

With compat-5.3.[ch] from 73fb49f I get following error:

gcc -O2 -fPIC -std=c89 -pedantic -Wall -Werror -O0 -g --coverage -DPACKAGE_STRING="\"LuaLDAP 1.2.3\"" -DLUA_C89_NUMBERS -I/opt/luaenv/versions/luajit-2.1.0-beta3/include/luajit-2.1 -I/usr/include -I/usr/include -I../compat/src   -c -o src/lualdap.o src/lualdap.c
In file included from src/compat-5.3.h:419:0,
                 from src/lualdap.c:26:
src/compat-5.3.c: In function 'compat53_strerror':
src/compat-5.3.c:59:9: error: implicit declaration of function 'strerror_r' [-Werror=implicit-function-declaration]
     if (strerror_r(en, buff, sz)) {
         ^~~~~~~~~~

For details see:

The strerror(3) manpage says:

SYNOPSIS
       #include <string.h>

       char *strerror(int errnum);

       int strerror_r(int errnum, char *buf, size_t buflen);
                   /* XSI-compliant */

       char *strerror_r(int errnum, char *buf, size_t buflen);
                   /* GNU-specific */

       char *strerror_l(int errnum, locale_t locale);

   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       strerror_r():
           The XSI-compliant version is provided if:
           (_POSIX_C_SOURCE >= 200112L) && !  _GNU_SOURCE
           Otherwise, the GNU-specific version is provided.

DESCRIPTION
       [...]

   strerror_r()
       The strerror_r() function is similar to strerror(), but is thread safe.  This function is available in two versions: an XSI-compliant version specified in POSIX.1-2001 (available since glibc 2.3.4, but not POSIX-compliant until glibc 2.13), and a GNU-specific version (available since glibc 2.0).  The XSI-compliant version is  provided  with  the
       feature test macros settings shown in the SYNOPSIS; otherwise the GNU-specific version is provided.  If no feature test macros are explicitly defined, then (since glibc 2.4) _POSIX_C_SOURCE is defined by default with the value 200112L, so that the XSI-compliant version of strerror_r() is provided by default.

However, the feature_test_macros(7) manpage appears to disagree (by stating that 200112L excludes the XSI extension):

DESCRIPTION
   [...]

   Feature test macros understood by glibc
       [...]

       _POSIX_C_SOURCE
               [...]

               ·  (Since glibc 2.3.3) The value 200112L or greater additionally exposes definitions corresponding to the POSIX.1-2001 base specification (excluding the XSI extension).  [...]

Hence I did not test setting _POSIX_C_SOURCE.

Defining _XOPEN_SOURCE=600 fixes the build. I suggest to add instructions regarding this fact to the readme.