- #include "apue.h"
-
#include <fcntl.h>
-
-
#define RWRWRW (S_IRUSR |S_IWUSR |S_IRGRP |S_IWGRP |S_IROTH |S_IWOTH )
-
-
int
-
main(void )
-
{
-
umask(0);
-
if (creat("foo",RWRWRW) < 0)
-
err_sys("create error");
-
umask(S_IRGRP |S_IWGRP | S_IROTH | S_IWOTH);
-
if (creat("bar",RWRWRW) < 0)
-
err_sys("create error");
-
exit(0);
-
}
ubuntu@ubuntu-virtual-machine:~/Desktop/apue$ umask
0002
ubuntu@ubuntu-virtual-machine:~/Desktop/apue$ ls -l foo bar
-rw------- 1 ubuntu ubuntu 0 2011-12-28 20:09 bar
-rw-rw-rw- 1 ubuntu ubuntu 0 2011-12-28 20:09 foo
ubuntu@ubuntu-virtual-machine:~/Desktop/apue$ umask
0002
ubuntu@ubuntu-virtual-machine:~/Desktop/apue$ umask -S
u=rwx,g=rwx,o=rx
PS:
子进程修改自己的文件模式屏蔽字,对父进程没有影响
文件最后的属性为:
mask&0777
建立文件 : 664 = 0666-0002
建立目录: 775 = 0777 - 0002
阅读(1013) | 评论(0) | 转发(0) |