Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX_SOURCE
#include <sys/stat.h>
mode_t umask(mode_t newmask);
Changes the file creation mask of the process. newmask specifies new file-permission bits for the file creation mask of the process.
This mask restricts the setting of (or turns off) file-permission bits specified in the ‘mode’ argument used with all open(), creat(), mkdir(), and mkfifo() functions issued by the current process. File-permission bits set to 1 in the file creation mask are set to 0 in the file-permission bits of files that are created by the process.
For example, if a call to open() specifies a mode argument with file-permission bits, the file creation mask of the process affects the mode argument; bits that are 1 in the mask are set to 0 in the mode argument, and therefore in the mode of the created file.
Only the file-permission bits of the new mask are used. The meaning of other bits is implementation-defined. For more information on these symbols, refer to chmod() — Change the mode of a file or directory.
Any other value for the environment variable causes the runtime library to use 022 octal as the umask value.
umask() is always successful and returns the previous value of the file creation mask.
There are no documented errno values.
⁄* CELEBU01
This example will work only from C⁄MVS, not C++⁄MVS.
*⁄
#define _POSIX_SOURCE
#include <fcntl.h>
#include <sys⁄stat.h>
#include <sys⁄types.h>
#include <unistd.h>
#undef _POSIX_SOURCE
#include <stdio.h>
main() {
int fd;
mode_t oldmask;
printf("Your old umask is %i\n",oldmask=umask(S_IRWXG));
if ((fd = creat("umask.file", S_IRWXU|S_IRWXG)) < 0)
perror("creat() error");
else {
system("ls -l umask.file");
close(fd);
unlink("umask.file");
}
umask(oldmask);
}
-rwx------ 1 WELLIE SYS1 0 Apr 19 14:50 umask.file