【问题标题】:No "renameat2" system call function on Ubuntu 16.04Ubuntu 16.04 上没有“renameat2”系统调用功能
【发布时间】:2017-01-14 21:54:32
【问题描述】:

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

当我做一个

cd /usr/include
grep -r renameat2

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

【问题讨论】:

  • 你有什么版本的glibc?什么版本的 Linux 内核?
  • Linux 内核是 4.4(系统调用是在 3.10 中添加的)Glibc 版本是 2.23

标签: c linux system-calls glibc


【解决方案1】:

好的,我在这里找到了答案,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);

【讨论】:

  • 来自未来的更新:从 2018 年 8 月 1 日发布的 glibc 2.28 开始,包含此函数的系统调用包装器。它没有赶上 18.04LTS,所以syscall-方法无论如何都会在接下来的 8 年多的时间里与我们同在……
猜你喜欢
  • 1970-01-01
  • 2017-11-04
  • 2020-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多