为什么对open的调用会在Linux上自动由openat代替?

问题描述

以下简单程序明确使用open()

#include <stdio.h>
#include <fcntl.h>
#include <errno.h>

int main(void) {
    int fd = open("/home/centos/AAA",O_RDONLY);
    if (fd < 0) {
        printf("open() returned ERROR\n");
        printf("errno: %d\n",errno);
        return 1;
    }
    return 0;
}

使用gcc进行编译,没有特殊标志:

gcc -Wall open_test.c -o open_test

但是,使用strace不会显示对open()的调用,而是显示对openat()的调用:

17893 openat(AT_FDCWD,"/home/centos/AAA",O_RDONLY) = 3

我了解使用openat()胜过open()的很多倍,但是哪一部分可以进行隐式替换,为什么呢?是编译器吗?操作系统?

平台
CentOS 8(内核4.18.0)
GCC 8.3.1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)