RFS | XFS
umask()
PROTOTYPE
#include <posix.h>
mode_t umask(mode_t cmask);
DESCRIPTION
umask() sets the system’s global file mode creation mask (umask) to cmask. umask impacts the permission bits applied when a new file is created.
The mode argument passed to open(), creat(), and mkdir() contains permission bits. freopen() and fopen() use 0666 as default permission bits. umask modifies these values as follows: any bit set in umask is cleared in the permission bits of the created file.
The default umask value is 002, which prevents the ‘other’ category from having write-access to new files. Some other common values and their effects are:
- 022 - Only the owner can write data.
- 077 - Only the owner can read or write data.
- 007 - Non-group members are completely excluded.
umask() returns the previous value of the file mode creation mask. A second call to umask() using the return value of the previous call restores the same state as before the first call.
EXAMPLE
/*-----------------------------------------------------------------*/
/* Re-assign the default file mode creation mask value. */
/*-----------------------------------------------------------------*/
umask(2);