所属类别:Linux
文章作者:joely.wu
特别推荐:免费发布信息 承包关键词~~抢爆了!HOT!
Linux系统调用--access函数详解2007-07-30 23:10
【access系统调用】功能描述:检查调用进程是否可以对指定的文件执行某种操作。用法:#include #include int access(const char *pathname, int mode); 参数:pathname: 需要测试的文件路径名。 mode: 需要测试的操作模式,可能值是一个或多个R_OK(可读?), W_OK(可写?), X_OK(可执行?) 或 F_OK(文件存在?)组合体。返回说明:成功执行时,返回0。失败返回-1,errno被设为以下的某个值EINVAL: 模式值无效 EACCES: 文件或路径名中包含的目录不可访问ELOOP : 解释路径名过程中存在太多的符号连接ENAMETOOLONG:路径名太长ENOENT: 路径名中的目录不存在或是无效的符号连接ENOTDIR: 路径名中当作目录的组件并非目录EROFS: 文件系统只读EFAULT: 路径名指向可访问的空间外EIO: 输入输出错误ENOMEM: 不能获取足够的内核内存ETXTBSY:对程序写入出错例子:/* test.c */#include #include #include #include int main(int argc, char *argv[]){ if (argc < 2) { printf("Usage: ./test filename\n"); exit(1); } if (access(argv[1], F_OK) == -1) { puts("File not exists!"); exit(2); } if (access(argv[1], R_OK) == -1) puts("You can't read the file!"); else if (access(argv[1], R_OK W_OK) != -1) puts("You can read and write the file"); else puts("You can read the file"); exit(0);}
相关信息· 对使用net程序架构开发的一点点儿
· 使用SWT开发WEB应用
· SUN公司即将完成JAVA语言的全部开源工作
· 咬文嚼字――3
37456
77806
