umask函数为进程设置文件模式创建屏蔽字,并返回以前的值。
#include
mode_t umask(mode_t cmask)
example:
#include
#include
#include
#define RWRWRW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
int main()
{
int value = umask(1);
printf("value last time = %d\n", value);
if (creat("foo", RWRWRW) < 0)
printf("create errno for foo ");
value = umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
printf("value last time = %d\n", value);
if (creat("bar", RWRWRW) < 0)
printf("create errno for bar");
exit(0);
return 0;
}
result:
value last time = 18
value last time = 1
#ls -l
-rw------- 1 root root 0 2010-04-28 16:49 bar
-rw-rw-rw- 1 root root 0 2010-04-28 16:49 foo
阅读(746) | 评论(0) | 转发(0) |