在Ubuntu 16.04上没有"renameat2"系统调用函数

Lot*_*har 4 c linux glibc system-calls

人工页面renameat2()说我需要包括<stdio.h>但这不起作用.

当我做的时候

cd /usr/include
grep -r renameat2
Run Code Online (Sandbox Code Playgroud)

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

Lot*_*har 6

好吧,我在这里找到了答案,glibc的一般问题是没有添加系统调用而且缺少手册页

注意:此系统调用没有glibc包装器; 见注意.

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

通过阅读本文找到答案 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);
Run Code Online (Sandbox Code Playgroud)