gtpc2m93 | C/C++ Language Support User's Guide |
This function sets the file mode creation mask.
Format
#include <sys/stat.h> mode_t umask(mode_t newmask);
This function changes the file creation mask of the process.
This mask controls file permission bits that should be set whenever the process creates a file. File permission bits that are 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 the open function 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. For more information about these symbols, see to chmod-Change the Mode of a File or Directory.
Normal Return
The umask function is always successful and returns the previous value of the file creation mask.
Error Return
Not applicable.
Programming Considerations
None.
Examples
#include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <stdio.h> main() { int fd; int save_mask = umask(S_IRWXG); if ((fd = creat("umask.file", S_IRWXU|S_IRWXG)) < 0) perror("creat() error"); else { close(fd); unlink("umask.file"); } }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.