apue umask 练习

 1 #include <sys/stat.h>
 2 #include <unistd.h>
 3 #include <stdlib.h>
 4 #include <fcntl.h>
 5 #include <stdio.h>
 6 
 7 #define  RWRWRW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
 8 int main(int argc, char const *argv[])
 9 {
10     
11     umask(0);
12     creat("foo",RWRWRW);
13     umask( S_IRGRP | S_IWUSR | S_IROTH | S_IWOTH);
14     creat("bar",RWRWRW);
15     printf("S_IRUSR = %d S_IWUSR= %d S_IRGRP= %d S_IWGRP = %d S_IROTH = %d S_IWOTH = %d RWRWRW=%d \n" ,\
16         S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP  ,S_IROTH, S_IWOTH, RWRWRW);
17     exit(0);
18 }

执行结果

[root@MiWiFi-R3-srv apue test]# ./unmaskt
S_IRUSR = 256 S_IWUSR= 128 S_IRGRP= 32 S_IWGRP = 16 S_IROTH = 4 S_IWOTH = 2 RWRWRW=438
[root@MiWiFi-R3-srv apue test]# ll bar foo
-r---w----. 1 root root 0 Aug 10 03:56 bar
-rw-rw-rw-. 1 root root 0 Aug 10 03:56 foo

posted @ 2017-12-19 23:28  蜗牛码  阅读(152)  评论(0编辑  收藏  举报