#include <sys/types.h>
#include <sys/stat.h>
mode_t umask(mode_t mask);
umask
0022
touch c.txt
ll c.txt
-rw-r--r-- 1 groad users 0 05-30 12:39 c.txt
mkdir
drwxr-xr-x 2 groad users 4096 05-30 12:42 temp_dir
umask 0000
ll d.txt
-rw-rw-rw- 1 groad users 0 05-30 12:43 d.txt
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
if (creat ("test01", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) < 0) {
perror ("creat");
exit (EXIT_FAILURE);
}
umask (0);
if (creat ("test02", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) < 0) {
perror ("creat");
exit (EXIT_FAILURE);
}
umask (S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (creat ("test03", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) < 0) {
perror ("creat");
exit (EXIT_FAILURE);
}
return (0);
}
> ll test01
-rw-r--r-- 1 groad users 0 05-30 14:14 test01
> ll test02
-rw-rw-rw- 1 groad users 0 05-30 14:14 test02
> ll test03
-rw------- 1 groad users 0 05-30 14:14 test03
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |