文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>access函数实例

access函数实例

时间:2010-12-24  来源:longmenyu

程序清单:

#include <stdio.h> //for printf

#include <stdlib.h> //for exit

#include <unistd.h> //for access

#include <fcntl.h> //for open


int main(int argc,char *argv[])
{
    if(argc != 2)
    {
        printf("usage:./a.out <pathname>");
        exit(1);    
    }
    if(access(argv[1],R_OK) < 0)
    {
        printf("access error for %s\n",argv[1]);
        exit(1);    
    }
    else
    {
        printf("read access OK\n");    
    }
    if(open(argv[1],O_RDONLY) < 0)
    {
        printf("open error for %s\n",argv[1]);
        exit(1);    
    }
    else
    {
        printf("open for reading OK\n");    
    }
    exit(0);
}

程序执行结果:
obe-240 test/linuxc> gcc access.c
obe-240 test/linuxc> ls -l a.out
-rwxr-xr-x 1 eagle hitv 9808 2010-12-24 10:31 a.out
obe-240 test/linuxc> ./a.out a.out
read access OK
open for reading OK
obe-240 test/linuxc> ls -l /etc/shadow
-rw-r----- 1 root shadow 1361 2010-10-19 19:22 /etc/shadow
obe-240 test/linuxc> ./a.out /etc/shadow
access error for /etc/shadow
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载