1 #include "apue.h"
2 #include <fcntl.h>
3
4 int main()
5 {
6 struct stat statbuf;
7 if( stat("without_umask",&statbuf) < 0)
8 err_sys("stat error");
9
10 if( chmod("without_umask", (statbuf.st_mode & ~S_IWGRP) | S_ISGID) < 0)
11 err_sys("chmod error");
12
13 if( chmod("after_umask", S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0)
14 err_sys("chmod2 error");
15
16 exit(0);
2 #include <fcntl.h>
3
4 int main()
5 {
6 struct stat statbuf;
7 if( stat("without_umask",&statbuf) < 0)
8 err_sys("stat error");
9
10 if( chmod("without_umask", (statbuf.st_mode & ~S_IWGRP) | S_ISGID) < 0)
11 err_sys("chmod error");
12
13 if( chmod("after_umask", S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0)
14 err_sys("chmod2 error");
15
16 exit(0);
17 }
-rw-r-Srw- 1 tingbinz tingbinz 0 Sep 14 02:31 without_umask
-rw-r--r-- 1 tingbinz tingbinz 0 Sep 14 02:31 after_umask