From 5a344d90c53d681ed98ab03ad3e218a3c6561108 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 17 Dec 2022 21:40:02 -0800 Subject: [PATCH] Port better to glibc 2.28+ renameat2 * configure.ac: Check for renameat2. * src/sysdep.c (renameat_noreplace): Prefer renameat2 (supplied by glibc 2.28 and later) to doing the syscall by hand. --- configure.ac | 1 + src/sysdep.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 6e37d56d316..67c393e3351 100644 --- a/configure.ac +++ b/configure.ac @@ -4997,6 +4997,7 @@ pthread_sigmask strsignal setitimer \ sendto recvfrom getsockname getifaddrs freeifaddrs \ gai_strerror sync \ getpwent endpwent getgrent endgrent \ +renameat2 \ cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np \ pthread_set_name_np]) LIBS=$OLD_LIBS diff --git a/src/sysdep.c b/src/sysdep.c index 736723bdf3d..8402ffe308c 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -2653,10 +2653,11 @@ emacs_perror (char const *message) int renameat_noreplace (int srcfd, char const *src, int dstfd, char const *dst) { -#if defined SYS_renameat2 && defined RENAME_NOREPLACE - return syscall (SYS_renameat2, srcfd, src, dstfd, dst, RENAME_NOREPLACE); -#elif defined CYGWIN && defined RENAME_NOREPLACE +#if HAVE_RENAMEAT2 && defined RENAME_NOREPLACE return renameat2 (srcfd, src, dstfd, dst, RENAME_NOREPLACE); +#elif defined SYS_renameat2 && defined RENAME_NOREPLACE + /* Linux kernel 3.15 (2014) or later, with glibc 2.27 (2018) or earlier. */ + return syscall (SYS_renameat2, srcfd, src, dstfd, dst, RENAME_NOREPLACE); #elif defined RENAME_EXCL return renameatx_np (srcfd, src, dstfd, dst, RENAME_EXCL); #else -- 2.39.2