]> 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>
Thu, 23 May 2024 13:23:13 +0000 (15:23 +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.
* doc/glibc-functions/renameat2.texi: Mention the Cygwin bug.

ChangeLog
doc/glibc-functions/renameat2.texi
lib/renameatu.c
m4/renameat.m4

index 9fb187b5cc0604df827b75ef5045d59280f627af..b3e5bcb5ee04726a245d8efc346e0bdd43a5b503 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+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.
+       * doc/glibc-functions/renameat2.texi: Mention the Cygwin bug.
+
 2024-05-23  Bruno Haible  <bruno@clisp.org>
 
        readlinkat, areadlinkat: Avoid test failures on Cygwin 3.4.6.
index ba577f4e2a829b91c4e3c8009583e93b8304f7cd..9588225f39de6b53e8c8e5c83dc49e8bcaf0fe79 100644 (file)
@@ -13,9 +13,12 @@ Portability problems fixed by Gnulib:
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function exists only on Linux and is therefore
-missing on many platforms:
-glibc 2.27, macOS 11.1, FreeBSD 14.0, NetBSD 10.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, Solaris 11.4, Cygwin 1.7.x, mingw, MSVC 14, Android API level 29.
+This function is missing on many platforms:
+glibc 2.27, macOS 11.1, FreeBSD 14.0, NetBSD 10.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, Solaris 11.4, Cygwin 2.8.x, mingw, MSVC 14, Android API level 29.
+@item
+This function succeeds when the @code{RENAME_NOREPLACE} flag is specified
+and the source and destination are the same file, on some platforms:
+Cygwin 3.4.6.
 @end itemize
 
 The @code{renameatu} module addresses some of these portability issues.
index 815e3e0da92c7302b5547900e3f2ec6592e7c850..437fc8f71a2151857809bd8afedc92e3de94ca56 100644 (file)
@@ -106,7 +106,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 565400f5db3960a481891ac49ac187087427ec74..adf1f6bdd0623e3246b5ddefb6f14f3cd1a08d5f 100644 (file)
@@ -1,5 +1,5 @@
 # renameat.m4
-# serial 4
+# serial 5
 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,
@@ -14,6 +14,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])
@@ -24,4 +25,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
 ])