From 3ff3e4eefb8996fab31cfc651ecd7cd3acddb965 Mon Sep 17 00:00:00 2001 From: Greg Hurrell Date: Sun, 18 Aug 2024 00:40:13 +0200 Subject: [PATCH] fix: fix a compilation error on GCC/Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit xstrdup.c:13:18: warning: implicit declaration of function ‘strdup’; did you mean ‘xstrdup’? [-Wimplicit-function-declaration] 13 | char *copy = strdup(str); | ^~~~~~ | xstrdup As Stack Overflow says: > It allows you to use functions that are not part of the standard C > library but are part of the POSIX.1 (IEEE Standard 1003.1) standard. > Using the macros described in feature_test_macros allows you to > control the definitions exposed by the system header files. > > As far as I know _POSIX_SOURCE is obsolete and you should use > _POSIX_C_SOURCE instead. > > For example, if you want to use strndup, you have to use > > #define _POSIX_C_SOURCE 200809L https://stackoverflow.com/a/48332467/2103996 And the libc manual: > Macro: _POSIX_C_SOURCE > > Define this macro to a positive integer to control which POSIX > functionality is made available. The greater the value of this macro, > the more functionality is made available. > > If you define this macro to a value greater than or equal to 1, then > the functionality from the 1990 edition of the POSIX.1 standard (IEEE > Standard 1003.1-1990) is made available. > > If you define this macro to a value greater than or equal to 2, then > the functionality from the 1992 edition of the POSIX.2 standard (IEEE > Standard 1003.2-1992) is made available. > > If you define this macro to a value greater than or equal to 199309L, > then the functionality from the 1993 edition of the POSIX.1b standard > (IEEE Standard 1003.1b-1993) is made available. > > If you define this macro to a value greater than or equal to 199506L, > then the functionality from the 1995 edition of the POSIX.1c standard > (IEEE Standard 1003.1c-1995) is made available. > > If you define this macro to a value greater than or equal to 200112L, > then the functionality from the 2001 edition of the POSIX standard > (IEEE Standard 1003.1-2001) is made available. > > If you define this macro to a value greater than or equal to 200809L, > then the functionality from the 2008 edition of the POSIX standard > (IEEE Standard 1003.1-2008) is made available. https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html --- lua/wincent/commandt/lib/xstrdup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/wincent/commandt/lib/xstrdup.c b/lua/wincent/commandt/lib/xstrdup.c index 4afe7ed4..727bd514 100644 --- a/lua/wincent/commandt/lib/xstrdup.c +++ b/lua/wincent/commandt/lib/xstrdup.c @@ -5,6 +5,8 @@ #include "xstrdup.h" +#define _POSIX_C_SOURCE 200809L /* needed in order to see strdup() */ + #include /* for NULL */ #include /* for abort() */ #include /* for strdup() */