程序清单:
#include <stdio.h> //for printf,perror
#include <stdlib.h> //for exit
#include <sys/stat.h> //for umask
/*注意:宏定义只能写在一行!!!*/
#define RWRWRW (S_IRUSR | S_IWUSR | S_IRGRP |S_IWGRP | S_IROTH | S_IWOTH)
int main(void)
{
/*创建第一个文件时,umask值为0,即为屏蔽任何权限位*/
umask(0);
if(creat("test1",RWRWRW) < 0)
{
perror("creat test1 error");
exit(1);
}
/*创建第二个文件时,umask禁止所有组和其他用户的访问权限*/
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if(creat("test2",RWRWRW) < 0)
{
perror("creat test2 error");
exit(1);
}
exit(0);
}
|
编译运行:
obe-240 test/linuxc> umask
22
obe-240 test/linuxc> ./umask
obe-240 test/linuxc> ls -l test1 test2
-rw-rw-rw- 1 eagle hitv 0 2010-12-24 13:34 test1
-rw------- 1 eagle hitv 0 2010-12-24 13:34 test2
obe-240 test/linuxc> umask
22
阅读(1726) | 评论(0) | 转发(0) |