bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* getcwd, getcwd-lgpl: Fix configure test
@ 2024-02-12 11:52 Bruno Haible
  0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2024-02-12 11:52 UTC (permalink / raw)
  To: bug-gnulib

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  <bruno@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
@@ -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.  */

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-12 11:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-12 11:52 getcwd, getcwd-lgpl: Fix configure test Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).