mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 12:26:52 +08:00
[libc][stdio] implement rename via SYS_renameat2 (#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: #84980 Link: #85068
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/stdio/rename.h"
|
||||
#include "include/llvm-libc-macros/linux/fcntl-macros.h"
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/common.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
@@ -15,7 +16,8 @@
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, rename, (const char *oldpath, const char *newpath)) {
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_rename, oldpath, newpath);
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_renameat2, AT_FDCWD, oldpath,
|
||||
AT_FDCWD, newpath, 0);
|
||||
|
||||
if (ret >= 0)
|
||||
return 0;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "include/llvm-libc-macros/linux/unistd-macros.h"
|
||||
#include "include/llvm-libc-macros/linux/sys-stat-macros.h"
|
||||
#include "include/llvm-libc-macros/linux/unistd-macros.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "src/fcntl/open.h"
|
||||
#include "src/stdio/rename.h"
|
||||
|
||||
Reference in New Issue
Block a user