1.函数功能:api
检查调用进程是否能够对指定的文件执行某种操做。微信
2.函数原型:ide
1)函数头文件函数
[cpp] view plain copy测试
#include <stdio.h> url
#include <unistd.h> spa
2)函数.net
[cpp] view plain copyblog
int access(const char * pathname, int mode) 进程
3)形参
pathname:须要检测的文件路劲名
mode:须要测试的操做模式。
4)函数返回值说明
成功执行时,返回0。失败返回-1,errno被设为如下的某个值
EINVAL: 模式值无效
EACCES: 文件或路径名中包含的目录不可访问
ELOOP : 解释路径名过程当中存在太多的符号链接
ENAMETOOLONG:路径名太长
ENOENT:路径名中的目录不存在或是无效的符号链接
ENOTDIR: 路径名中看成目录的组件并不是目录
EROFS: 文件系统只读
EFAULT: 路径名指向可访问的空间外
EIO:输入输出错误
ENOMEM: 不能获取足够的内核内存
ETXTBSY:对程序写入出错
5)mode说明
[cpp] view plain copy
R_OK 测试读许可权
W_OK 测试写许可权
X_OK 测试执行许可权
F_OK 测试文件是否存在
3.函数实例
[cpp] view plain copy
#include <stdio.h>
#include <unistd.h>
int main(void)
{
if(access("test.txt", R_OK)==0) printf("READ OK\n");
if(access("test.txt", W_OK)==0) printf("WRITE OK\n");
if(access("test.txt", X_OK)==0) printf("EXEC OK\n");
if(access("test.txt", F_OK)==0) printf("File exist\n");
}