rename, renameat: Use renameat2() system call
authorBen Hutchings <ben@decadent.org.uk>
Mon, 16 Jul 2018 17:24:08 +0000 (18:24 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 6 Jan 2019 19:33:01 +0000 (19:33 +0000)
New architectures only define the renameat2() system call, which was
added in Linux 3.15.  Define rename() and renameat() as wrappers for
it if necessary.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Name rename-renameat-use-rename2-system-call.patch

usr/klibc/Kbuild
usr/klibc/SYSCALLS.def
usr/klibc/rename.c
usr/klibc/renameat.c [new file with mode: 0644]

index 3837e95e8602be3b635d374718fd15719e279bab..15bc26ab115d1c79c7bfa47583f04649bc9b6ec3 100644 (file)
@@ -59,7 +59,8 @@ klib-y += vsnprintf.o snprintf.o vsprintf.o sprintf.o \
          inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \
          inet/inet_ntop.o inet/inet_pton.o inet/bindresvport.o \
          accept.o send.o recv.o \
-         access.o chmod.o chown.o dup2.o mknod.o poll.o rename.o stat.o \
+         access.o chmod.o chown.o dup2.o mknod.o poll.o rename.o renameat.o \
+         stat.o \
          lchown.o link.o rmdir.o unlink.o utimes.o lstat.o mkdir.o \
          readlink.o select.o symlink.o pipe.o \
          ctype/isalnum.o ctype/isalpha.o ctype/isascii.o \
index c56e8f997838143c4ab226d13801ba117a5e3b65..64d7b0c13766653b15fa793f1691e9e8901a941b 100644 (file)
@@ -116,6 +116,7 @@ int chdir(const char *);
 int fchdir(int);
 <?> int rename(const char *, const char *);
 <?> int renameat(int, const char *, int, const char *);
+<?> int renameat2(int, const char *, int, const char *, unsigned int);
 <?> int mknod(const char *, mode_t, dev_t);
 <?> int mknodat(int, const char *, mode_t, dev_t);
 <?> int chmod(const char *, mode_t);
index 587c26f8b4983e5706a62392f90b852aa7640ba1..d76b7397502ab524044aa963876fbb689a9cc70a 100644 (file)
@@ -5,7 +5,7 @@
 
 int rename(const char *oldpath, const char *newpath)
 {
-       return renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
+       return renameat2(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);
 }
 
 #endif /* __NR_rename */
diff --git a/usr/klibc/renameat.c b/usr/klibc/renameat.c
new file mode 100644 (file)
index 0000000..10c8882
--- /dev/null
@@ -0,0 +1,12 @@
+#include <fcntl.h>
+#include <stdio.h>
+
+#ifndef __NR_renameat
+
+int renameat(int olddirfd, const char *oldpath,
+            int newdirfd, const char *newpath)
+{
+       return renameat2(olddirfd, oldpath, newdirfd, newpath, 0);
+}
+
+#endif /* __NR_renameat */