euidaccess函数用法详解
euidaccess函数简介
- 头文件包含
#include <unistd.h>
- 函数定义
int euidaccess(const char * pathname , int mode );
int eaccess(const char * pathname , int mode );
euidaccess函数常见使用错误
- 编译错误
warning: implicit declaration of function ‘euidaccess’ [-Wimplicit-function-declaration]
解决办法:包含头文件
#include <unistd.h>
euidaccess函数详细描述
然而,与access (2)一样,euidaccess ()检查权限以及由其参数pathname 标识的文件的存在,而access (2)使用进程的真实用户和组标识符来执行检查,而euidaccess ()使用有效标识符。
mode是由一个或多个具有与access (2)相同含义的R_OK " " W_OK " " X_OK " and " F_OK 组成的掩码
eaccess ()是euidaccess ()的同义词,用于与其他一些系统兼容。
euidaccess函数返回值
如果成功(所有请求的权限都被授予),则返回零。如果出现错误(至少mode中的一位请求权限被拒绝,或者发生了其他错误),则返回-1,并适当地设置errno。
euidaccess函数错误码
至于access (2)
euidaccess函数其他说明
Warning :在基于该信息执行某些操作之前,使用此函数检查进程对文件的权限会导致争用条件:文件权限可能会在两个步骤之间发生变化。通常,更安全的做法是尝试所需的操作并处理发生的任何权限错误。
这个函数总是取消对符号链接的引用。如果需要检查符号链接的权限,请使用带有标志AT_EACCESS和AT_SYMLINK_NOFOLLOW 的faccessat (2)
评论区