]> Savannah Git Hosting - gnulib.git/commitdiff
renameatu: Work around Cygwin 3.4.6 bug.
authorBruno Haible <bruno@clisp.org>
Thu, 23 May 2024 13:15:40 +0000 (15:15 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 31 May 2024 21:44:06 +0000 (23:44 +0200)
* m4/renameat.m4 (gl_FUNC_RENAMEAT): Test whether renameat2 works, and
define HAVE_WORKING_RENAMEAT2 if so.
* lib/renameatu.c (renameatu): Test HAVE_WORKING_RENAMEAT2 instead of
HAVE_RENAMEAT2.

ChangeLog
lib/renameatu.c
m4/renameat.m4

index 508d67dccb66d1ee24c0628dce702f0c4b41674e..ebbe06fe7378e896434eee86cd835ca273f26291 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-05-23  Bruno Haible  <bruno@clisp.org>
+
+       renameatu: Work around Cygwin 3.4.6 bug.
+       * m4/renameat.m4 (gl_FUNC_RENAMEAT): Test whether renameat2 works, and
+       define HAVE_WORKING_RENAMEAT2 if so.
+       * lib/renameatu.c (renameatu): Test HAVE_WORKING_RENAMEAT2 instead of
+       HAVE_RENAMEAT2.
+
 2024-05-23  Bruno Haible  <bruno@clisp.org>
 
        readlinkat, areadlinkat: Avoid test failures on Cygwin 3.4.6.
index c9c84f27b8d212b7f93ea111e925c9a6becc1e35..6f48bc83d77cc5f5d36f959fdb439cd09533a76f 100644 (file)
@@ -102,7 +102,7 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
   int ret_val = -1;
   int err = EINVAL;
 
-#ifdef HAVE_RENAMEAT2
+#if HAVE_WORKING_RENAMEAT2
   ret_val = renameat2 (fd1, src, fd2, dst, flags);
   err = errno;
 #elif defined SYS_renameat2
index 37805786636758e0f7b88e140cae5e4688d10e99..be7848e4f9cc33e3ccb0b8a36143b88c82926522 100644 (file)
@@ -1,7 +1,7 @@
-# serial 4
+# serial 5
 # See if we need to provide renameat replacement.
 
-dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
+dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -13,6 +13,7 @@ AC_DEFUN([gl_FUNC_RENAMEAT],
   AC_REQUIRE([gl_FUNC_OPENAT])
   AC_REQUIRE([gl_FUNC_RENAME])
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
   AC_CHECK_HEADERS([linux/fs.h])
   AC_CHECK_FUNCS_ONCE([renameat])
@@ -23,4 +24,39 @@ AC_DEFUN([gl_FUNC_RENAMEAT],
     REPLACE_RENAMEAT=1
   fi
   gl_CHECK_FUNCS_ANDROID([renameat2], [[#include <stdio.h>]])
+  if test $ac_cv_func_renameat2 = yes; then
+    AC_CACHE_CHECK([whether renameat2 works],
+      [gl_cv_func_renameat2_works],
+      [AC_RUN_IFELSE(
+         [AC_LANG_SOURCE([[
+            #include <fcntl.h>
+            #include <stdio.h>
+            int main ()
+            {
+              /* This test fails on Cygwin 3.4.6.  */
+              if (renameat2 (AT_FDCWD, "conftest.c", AT_FDCWD, "conftest.c",
+                             RENAME_NOREPLACE) == 0)
+                return 1;
+              return 0;
+            }
+         ]])],
+         [gl_cv_func_renameat2_works=yes],
+         [gl_cv_func_renameat2_works=no],
+         [case "$host_os" in
+                     # Guess yes on Linux.
+            linux*)  gl_cv_func_renameat2_works="guessing yes" ;;
+                     # Guess no on Cygwin.
+            cygwin*) gl_cv_func_renameat2_works="guessing no" ;;
+                     # If we don't know, obey --enable-cross-guesses.
+            *)       gl_cv_func_renameat2_works="$gl_cross_guess_normal" ;;
+          esac
+         ])
+      ])
+    case "$gl_cv_func_renameat2_works" in
+      *yes)
+        AC_DEFINE([HAVE_WORKING_RENAMEAT2], [1],
+          [Define if the renameat2 function exists and it works.])
+        ;;
+    esac
+  fi
 ])