Ubuntu 16.04 上没有 "renameat2" 系统调用函数
No "renameat2" system call function on Ubuntu 16.04
renameat2()
的手册页说我需要包括 <stdio.h>
但这不起作用。
当我做
cd /usr/include
grep -r renameat2
我看到 __SYSCALL 已定义但没有 glibc 函数。系统调用的标志在 <linux/fs.h>
中可用,但不包括在内。
好的,我在这里找到了答案,glibc 没有添加系统调用的一般问题和手册页缺少
Note: There is no glibc wrapper for this system call; see 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);
renameat2()
的手册页说我需要包括 <stdio.h>
但这不起作用。
当我做
cd /usr/include
grep -r renameat2
我看到 __SYSCALL 已定义但没有 glibc 函数。系统调用的标志在 <linux/fs.h>
中可用,但不包括在内。
好的,我在这里找到了答案,glibc 没有添加系统调用的一般问题和手册页缺少
Note: There is no glibc wrapper for this system call; see 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);