Linux access/faccessat/eaccess 函数

本文介绍了Linux中access、faccessat和eaccess函数的用法,通过实例展示了这三个函数在权限测试上的区别。access通过实际UID、GID检查,eaccess使用有效UID,faccessat可由flag参数调整。同时,文章提到了S_ISUID的影响,当设置S_ISUID后,程序会以文件所有者权限运行,这在权限检查上产生了不同结果。
摘要由CSDN通过智能技术生成

一、函数声明

https://man7.org/linux/man-pages/man2/access.2.html中的定义

#include <unistd.h>

int access(const char *pathname, int mode);

#include <fcntl.h>           /* Definition of AT_* constants */
#include <unistd.h>

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

gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0 unistd.h中的定义

/* Values for the second argument to access.
   These may be OR'd together.  */
#define	R_OK	4		/* Test for read permission.  */
#define	W_OK	2		/* Test for write permission.  */
#define	X_OK	1		/* Test for execute permission.  */
#define	F_OK	0		/* Test for existence. 测试文件是否存在 */

/* Test for access to NAME using the real UID and real GID.  */
extern int access (const char *__name, int __type) __THROW __nonnull ((1));

#ifdef __USE_GNU
/* Test for access to NAME using the effective UID and GID
   (as normal file operations use).  */
extern int euidaccess (const char *__name, int __type)
     __THROW __nonnull 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值