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
23 elif test $REPLACE_RENAME = 1; then
24 dnl Solaris 9 and 10 have the same bugs in renameat as in rename.
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],
37 /* This test fails on Cygwin 3.4.6. */
38 if (renameat2 (AT_FDCWD, "conftest.c", AT_FDCWD, "conftest.c",
39 RENAME_NOREPLACE) == 0)
44 [gl_cv_func_renameat2_works=yes],
45 [gl_cv_func_renameat2_works=no],
48 linux*) gl_cv_func_renameat2_works="guessing yes" ;;
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" ;;
56 case "$gl_cv_func_renameat2_works" in
58 AC_DEFINE([HAVE_WORKING_RENAMEAT2], [1],
59 [Define if the renameat2 function exists and it works.])