windows-once: Improve comments.
[gnulib.git] / m4 / renameat.m4
blobadf1f6bdd0623e3246b5ddefb6f14f3cd1a08d5f
1 # renameat.m4
2 # serial 5
3 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # See if we need to provide renameat replacement.
10 # Written by Eric Blake.
12 AC_DEFUN([gl_FUNC_RENAMEAT],
14   AC_REQUIRE([gl_FUNC_OPENAT])
15   AC_REQUIRE([gl_FUNC_RENAME])
16   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
17   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
18   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
19   AC_CHECK_HEADERS([linux/fs.h])
20   AC_CHECK_FUNCS_ONCE([renameat])
21   if test $ac_cv_func_renameat = no; then
22     HAVE_RENAMEAT=0
23   elif test $REPLACE_RENAME = 1; then
24     dnl Solaris 9 and 10 have the same bugs in renameat as in rename.
25     REPLACE_RENAMEAT=1
26   fi
27   gl_CHECK_FUNCS_ANDROID([renameat2], [[#include <stdio.h>]])
28   if test $ac_cv_func_renameat2 = yes; then
29     AC_CACHE_CHECK([whether renameat2 works],
30       [gl_cv_func_renameat2_works],
31       [AC_RUN_IFELSE(
32          [AC_LANG_SOURCE([[
33             #include <fcntl.h>
34             #include <stdio.h>
35             int main ()
36             {
37               /* This test fails on Cygwin 3.4.6.  */
38               if (renameat2 (AT_FDCWD, "conftest.c", AT_FDCWD, "conftest.c",
39                              RENAME_NOREPLACE) == 0)
40                 return 1;
41               return 0;
42             }
43          ]])],
44          [gl_cv_func_renameat2_works=yes],
45          [gl_cv_func_renameat2_works=no],
46          [case "$host_os" in
47                      # Guess yes on Linux.
48             linux*)  gl_cv_func_renameat2_works="guessing yes" ;;
49                      # Guess no on Cygwin.
50             cygwin*) gl_cv_func_renameat2_works="guessing no" ;;
51                      # If we don't know, obey --enable-cross-guesses.
52             *)       gl_cv_func_renameat2_works="$gl_cross_guess_normal" ;;
53           esac
54          ])
55       ])
56     case "$gl_cv_func_renameat2_works" in
57       *yes)
58         AC_DEFINE([HAVE_WORKING_RENAMEAT2], [1],
59           [Define if the renameat2 function exists and it works.])
60         ;;
61     esac
62   fi