LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1352|回复: 2

access函数测试所有的文件的存取许可权都成功了?

[复制链接]
发表于 2006-9-11 22:43:51 | 显示全部楼层 |阅读模式
  1. #include        <sys/types.h>
  2. #include        <sys/stat.h>
  3. #include        <fcntl.h>
  4. #include        "ourhdr.h"

  5. //#define        BUF_SIZE        11

  6. int main(int argc, char *argv[])
  7. {
  8.         if (argc != 2)
  9.                 err_quit("usage: a.out <pathname>");

  10.         if (access(argv[1], R_OK) < 0)
  11.                 err_ret("access error for %s", argv[1]);
  12.         else
  13.                 printf("access OK\n");

  14.         if ( open(argv[1], O_RDONLY) < 0)
  15.                 err_ret("open error for %s", argv[1]);
  16.         else
  17.                 printf("open for reading OK\n");


  18. exit(0);
  19. }
复制代码

  1. ysm@YSM:/bak/cai$ ls -l /y.c
  2. -rw-r--r--  1 root root 436 2006-09-11 23:14 /y.c

  3. ysm@YSM:/bak/cai$ ./a.out /y.c
  4. access OK
  5. open for reading OK
  6. ysm@YSM:/bak/cai$
复制代码
发表于 2006-9-12 15:32:30 | 显示全部楼层
你这个 /y.c 不是有 r 权限嘛, 哪里不对
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-18 22:38:01 | 显示全部楼层
Post by DoDo
你这个 /y.c 不是有 r 权限嘛, 哪里不对


呵呵,这个细节没注意,谢谢了:p
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表