Linux系统调用--access函数详解
2010-01-20 11:16
393 查看
Linux系统调用--access函数详解
2007-07-30 23:10
【access系统调用】
功能描述:
检查调用进程是否可以对指定的文件执行某种操作。
用法:
#include <unistd.h>
#include <fcntl.h>
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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
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);
文章出处:DIY部落(http://www.diybl.com/course/6_system/linux/Linuxjs/20081012/150297.html)
2007-07-30 23:10
【access系统调用】
功能描述:
检查调用进程是否可以对指定的文件执行某种操作。
用法:
#include <unistd.h>
#include <fcntl.h>
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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
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);
文章出处:DIY部落(http://www.diybl.com/course/6_system/linux/Linuxjs/20081012/150297.html)
相关文章推荐
- Linux系统调用--access函数详解
- Linux系统调用--getitimer/setitimer函数详解
- Linux系统调用fork()用法详解
- Linux系统调用详解(实现机制分析)--linux内核剖析(六)
- Linux系统调用--getrlimit()与setrlimit()函数详解
- Linux系统调用--msgsnd/msgrcv函数详解
- Linux系统调用--ptrace函数详解
- linux内核剖析---Linux系统调用详解(实现机制分析)
- Linux系统调用--fcntl函数详解
- Linux系统调用--msgsnd/msgrcv函数详解
- Linux系统调用--getrlimit/setrlimit函数详解
- Linux 内核0.11 系统调用详解(下)
- Linux系统调用--getrlimit()与setrlimit()函数详解
- Linux系统调用--fcntl函数详解
- linux 系统调用详解
- Linux系统调用--getrlimit()与setrlimit()函数详解
- Linux系统调用fsync函数详解
- strace命令_Linux strace 命令用法详解:跟踪系统调用和信号
- Linux系统调用--getitimer/setitimer函数详解
- Linux内存管理之mmap详解 一. mmap系统调用 1. mmap系统调用 mmap将一个文件或者其它对象映射进内存。文件被映射到多个页上,如果文件的大小不是所有页的大小之和,