openat

阅读android的init代码中uevent部分时,发现openat系统调用。小记一下:


       #include <fcntl.h>

       int openat(int dirfd, const char *pathname, int flags);
       int openat(int dirfd, const char *pathname, int flags, mode_t mode);


openat系统调用与open功能类似,但用法上有以下不同:

1. 如果pathname是相对地址,以dirfd作为相对地址寻址目录。而open是从当前目录开始寻址的。

2. 如果pathname是相对地址,且dirfd的值是AT_FDCWD,则openat的行为与open一样,从当前目录开始相对寻址。

3. 如果pathname是绝对地址,则dirfd参数不起作用。


成功返回新的文件描述符,出错返回-1。

原文地址:https://www.cnblogs.com/sammei/p/3295604.html