1c04807c8Saniplcc //===-- Linux implementation of rename ------------------------------------===// 2c04807c8Saniplcc // 3c04807c8Saniplcc // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4c04807c8Saniplcc // See https://llvm.org/LICENSE.txt for license information. 5c04807c8Saniplcc // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6c04807c8Saniplcc // 7c04807c8Saniplcc //===----------------------------------------------------------------------===// 8c04807c8Saniplcc 9c04807c8Saniplcc #include "src/stdio/rename.h" 10*7b663bd9SJob Henandez Lara #include "hdr/fcntl_macros.h" 11c04807c8Saniplcc #include "src/__support/OSUtil/syscall.h" // For internal syscall function. 12c04807c8Saniplcc #include "src/__support/common.h" 135ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 14c04807c8Saniplcc #include "src/errno/libc_errno.h" 15c04807c8Saniplcc #include <sys/syscall.h> // For syscall numbers. 16c04807c8Saniplcc 175ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 18c04807c8Saniplcc 19c04807c8Saniplcc LLVM_LIBC_FUNCTION(int, rename, (const char *oldpath, const char *newpath)) { 206eff53b4SNick Desaulniers int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_renameat2, AT_FDCWD, oldpath, 216eff53b4SNick Desaulniers AT_FDCWD, newpath, 0); 22c04807c8Saniplcc 23c04807c8Saniplcc if (ret >= 0) 24c04807c8Saniplcc return 0; 25c04807c8Saniplcc libc_errno = -ret; 26c04807c8Saniplcc return -1; 27c04807c8Saniplcc } 28c04807c8Saniplcc 295ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 30