Skip to content

Commit bd259b0

Browse files
nickdesaulnierschencha3
authored andcommitted
[libc][stdio] implement rename via SYS_renameat2 (llvm#86140)
SYS_rename may be unavailable on architectures such as aarch64 and riscv. rename can be implemented in terms of SYS_rename, SYS_renameat, or SYS_renameat2. I don't have a full picture of the history here, but it seems that SYS_renameat might also be unavailable on some platforms. `man 2 rename` mentions that SYS_renameat2 was added in Linux 3.15. We don't need to support such ancient kernel versions prior. Link: llvm#84980 Link: llvm#85068
1 parent 7fc6a66 commit bd259b0

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

libc/src/stdio/linux/rename.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/stdio/rename.h"
10+
#include "include/llvm-libc-macros/linux/fcntl-macros.h"
1011
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1112
#include "src/__support/common.h"
1213
#include "src/errno/libc_errno.h"
@@ -15,7 +16,8 @@
1516
namespace LIBC_NAMESPACE {
1617

1718
LLVM_LIBC_FUNCTION(int, rename, (const char *oldpath, const char *newpath)) {
18-
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_rename, oldpath, newpath);
19+
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_renameat2, AT_FDCWD, oldpath,
20+
AT_FDCWD, newpath, 0);
1921

2022
if (ret >= 0)
2123
return 0;

libc/test/src/stdio/rename_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "include/llvm-libc-macros/linux/unistd-macros.h"
109
#include "include/llvm-libc-macros/linux/sys-stat-macros.h"
10+
#include "include/llvm-libc-macros/linux/unistd-macros.h"
1111
#include "src/errno/libc_errno.h"
1212
#include "src/fcntl/open.h"
1313
#include "src/stdio/rename.h"

0 commit comments

Comments
 (0)