[libc-commits] [libc] [libc][stdio] implement rename via SYS_renameat2 (PR #86140)

via libc-commits libc-commits at lists.llvm.org
Thu Mar 21 08:55:01 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

<details>
<summary>Changes</summary>

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.

Link: #<!-- -->84980
Link: #<!-- -->85068


---
Full diff: https://github.com/llvm/llvm-project/pull/86140.diff


1 Files Affected:

- (modified) libc/src/stdio/linux/rename.cpp (+2-1) 


``````````diff
diff --git a/libc/src/stdio/linux/rename.cpp b/libc/src/stdio/linux/rename.cpp
index f3d684249ad28e..afa025864fb1c5 100644
--- a/libc/src/stdio/linux/rename.cpp
+++ b/libc/src/stdio/linux/rename.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "include/llvm-libc-macros/linux/fcntl-macros.h"
 #include "src/stdio/rename.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
@@ -15,7 +16,7 @@
 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;

``````````

</details>


https://github.com/llvm/llvm-project/pull/86140


More information about the libc-commits mailing list