c语言 - Ubuntu 16.04 上没有"renameat2"系统调用函数



renameat2()的手册页说我需要包含<stdio.h>但这不起作用。

当我做一个

cd /usr/include
grep -r renameat2

我看到__SYSCALL已定义,但没有 glibc 函数。系统调用的标志在<linux/fs.h>中可用,但不包括在内。

好的,我在这里找到了答案,glibc 不添加系统调用和手册页缺少的一般问题

注意:此系统调用没有 glibc 包装器;请参阅 NOTES。

注释显示在其他页面上。所以我感到困惑。

通过阅读本文找到答案https://lwn.net/Articles/655028/

这是代码

#include <sys/syscall.h>
#include <linux/fs.h>
//Open the old directories to obtain fds
int src_fd = open("old_dir", O_PATH);
int dest_fd = open("new_dir", O_PATH);
const char* src_path = "old_name.txt";
const char* dest_path = "new_name.txt";
unsigned int flags = RENAME_NOREPLACE;
int rc = syscall(SYS_renameat2, src_fd, src_path, dest_fd, dest_path, flags);

最新更新