umask 等函数运行错误
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.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)
printf("creat error for foo");
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (creat("bar", RWRWRW) < 0)
printf("creat error for bar");
exit(0);
}
结果是#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.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)
printf("creat error for foo");
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (creat("bar", RWRWRW) < 0)
printf("creat error for bar");
exit(0);
}
求解释
-rwxrwxrwx. 1 root root 0 2011-03-04 07:44 bar
-rwxrwxrwx. 1 root root 0 2011-03-04 07:44 foo
-rwxrwxrwx. 1 root root 0 2011-03-04 07:44 foo