- 论坛徽章:
- 0
|
access函数(测试文件的访问类型)
使用格式:
status = access (file,mode ) ;
各参数定义:
n file:文件名。
n mode:一般可以是下列值(注意,下列值以0开头,代表八进制)。
u 04:代表读
u 02:代表写
u 01:代表可执行
u status:如果函数调用成功,则系统返回0给status,如失败,返回-1。另外,这个域也可省略。
Code:
main()
{
static char file[] = "t1.txt" ;
if ( access(file,01) == -1 )
{
fprintf(stderr,"read file [%s] error \n",file) ;
exit(1) ;
}
printf("#%s# is readable\n",file) ;
exit(0) ;
}
程序执行结果:
$ ls -l t1.txt
-rwxr-xr-x 1 test staff 0 Sep 15 15:14 t1.txt
$cc –o access access.c;access
#t1.txt# is readable
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/22541/showart_173944.html |
|