On a glibc system, with clang 17 and CC="clang -std=gnu2x", the configure test
checking whether getcwd (NULL, 0) allocates memory for result... reports 'no' instead of 'yes'. This is because of this compilation error: conftest.c:169:16: error: conflicting types for 'getcwd' 169 | char *getcwd (); | ^ /usr/include/unistd.h:531:14: note: previous declaration is here 531 | extern char *getcwd (char *__buf, size_t __size) __THROW __wur; | ^ We cannot easily change this declaration to char *getcwd (char *, size_t); because that would lead to a compilation error on native Windows (where the second argument's type is 'int'). Nowadays, redeclaring system functions is no longer needed. It was needed in the 1990ies (think of SunOS 4), when system header files did not provide C89 prototypes for system functions. But then, 1. the advent of C++ with its requirement for function prototypes, 2. the support of 64-bit platforms forced the vendors to declare system functions properly. 2024-02-12 Bruno Haible <br...@clisp.org> getcwd, getcwd-lgpl: Fix configure test. * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): Don't redeclare getcwd(). diff --git a/m4/getcwd.m4 b/m4/getcwd.m4 index 558a032f1b..ed3d7b610a 100644 --- a/m4/getcwd.m4 +++ b/m4/getcwd.m4 @@ -6,7 +6,7 @@ # with or without modifications, as long as this notice is preserved. # Written by Paul Eggert. -# serial 21 +# serial 22 AC_DEFUN([gl_FUNC_GETCWD_NULL], [ @@ -21,11 +21,8 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL] # else /* on Windows with MSVC */ # include <direct.h> # endif - ]GL_MDA_DEFINES[ -# ifndef getcwd - char *getcwd (); -# endif -]], [[ + ]GL_MDA_DEFINES], + [[ #if defined _WIN32 && ! defined __CYGWIN__ /* mingw cwd does not start with '/', but _getcwd does allocate. However, mingw fails to honor non-zero size. */