umask
时间:2010-04-28 来源:checl1987_EE
umask函数为进程设置文件模式创建屏蔽字,并返回以前的值。
#include<sys/stat.h>
mode_t umask(mode_t cmask)
example: #include<sys/stat.h> #include<stdio.h> #include<stdlib.h> #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
example: #include<sys/stat.h> #include<stdio.h> #include<stdlib.h> #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
相关阅读 更多 +