#include <sys/stat.h> mode_t umask(mode_t cmask);Service Program Name: QP0LLIB1
Every job has a file creation mask. When a job starts, the value of the file creation mask is zero. The value of zero means that no permissions are masked when a file or directory is created in the job. The umask() function changes the value of the file creation mask for the current job to the value specified in cmask.
The cmask argument controls file permission bits that should be set whenever the job creates a file. 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 job.
For example, if a call to open() specifies a mode argument with file permission bits, the file creation mask of the job 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 cmask are used. The other bits in cmask must be cleared (not set), or the CPFA0D3 message is issued.
No authorization is required.
umask() returns the previous value of the file creation mask. It does not return -1 or set the errno global variable.
None.
The following messages may be sent from this function:
Message ID | Error Message Text |
---|---|
CPE3418 E | Possible APAR condition or hardware failure. |
CPFA0D3 E | cmask parameter is not valid. |
CPFA0D4 E | File system error occurred. Error number &1. |
CPF3CF2 E | Error(s) occurred during running of &1 API. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
umask() does not update the file creation mask for QNTC. The settings specified in cmask are ignored.
See Code disclaimer information for information pertaining to code examples.
The following example uses umask():
#include <stdio.h> #include <fcntl.h> #include <sys/stat.h> main() { int file_descriptor; struct stat info; umask(S_IRWXG); if ((file_descriptor = creat("umask.file", S_IRWXU|S_IRWXG)) < 0) perror("creat() error"); else { fstat(file_descriptor, &info); printf("permissions are: %08x\n", info.st_mode); close(file_descriptor); unlink("umask.file"); } }
Output:
permissions are: 000081c0
Top | UNIX-Type APIs | APIs by category |