Set the file-mode creation mask for the process
#include <sys/types.h> #include <sys/stat.h> mode_t umask( mode_t cmask );
Owner | Group | Others | Permission |
---|---|---|---|
S_IRUSR | S_IRGRP | S_IROTH | Read |
S_IRWXU | S_IRWXG | S_IRWXO | Read, write, execute/search. A bitwise inclusive OR of the other three constants. (S_IRWXU is OR of IRUSR, S_IWSUR and S_IXUSR.) |
S_IWUSR | S_IWGRP | S_IWOTH | Write |
S_IXUSR | S_IXGRP | S_IXOTH | Execute/search |
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The umask() function sets the process's file-mode creation mask to cmask, and returns the previous value of the mask. Only the file permission bits (as defined in <sys/stat.h>) are used.
The file-mode creation mask for the process is used when you call creat(), mkdir(), mkfifo(), and open(), to turn off permission bits in the mode argument supplied. Bit positions set in cmask are cleared in the mode of the created file.
The previous value of the file-mode creation mask.
/* * Set the umask to RW for owner,group; R for other */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> int main( void ) { mode_t omask; mode_t nmask; nmask = S_IRUSR | S_IWUSR | /* owner read write */ S_IRGRP | S_IWGRP | /* group read write */ S_IROTH; /* other read */ omask = umask( nmask ); printf( "Mask changed from %o to %o\n", omask, nmask ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
chmod(), creat(), mkdir(), mkfifo(), open(), stat()