Chinaunix首页 | 论坛 | 博客
  • 博客访问: 71541
  • 博文数量: 28
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 291
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-29 14:47
文章存档

2014年(13)

2013年(15)

我的朋友

分类: C/C++

2013-12-03 17:20:18

access函数是按实际用户ID和实际组ID进行存取许可权测试的。
#include  int access(const char pathname,int mode);
mode参数 R_OK 测试读许可权  W_OK 测试写许可权
         X_OK 测试执行许可权 F_OK测试文件是否存在
#include "ourhdr.h"

void err_quit(char *str);
int main(int argc,char *argv[])
{
  if(argc!=2)
    err_quit("usage: a.out ");

  if(access(argv[1],R_OK)<0)
    printf("access error for %s",argv[1]);
  else
    printf("read access OK\n");

  if(open(argv[1],O_RDONLY)<0)
    printf("open error for %s",argv[1]);
  else
    printf("open for reading OK\n");
  exit(0);
}

umask函数为进程设置文件方式创建屏蔽字,并返回以前的值
#include "ourhdr.h"

int main(void)
{
  umask(0);
疑问?用户执行权限无法获得  需要删除以前创建的文件
  if(creat("foo",S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|
                                S_IROTH|S_IWOTH)<0)
    printf("creat error for foo");
  umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); //屏蔽了S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH这四个权限
  if(creat("bar",S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|
                                  S_IROTH|S_IWOTH)<0)
     printf("creat error for bar");
  exit(0);
}

阅读(755) | 评论(0) | 转发(0) |
0

上一篇:lseek解析

下一篇:fork函数

给主人留下些什么吧!~~