### umask -- Sets File Mask of Current Process

Format

>     #include <io.h>
>     #include <sys\stat.h>
>     int umask(int pmode);

Language Level: XPG4, Extension
umask sets the file permission mask of the environment for the currently running process to the mode specified by pmode. The file permission mask modifies the permission setting of new files created by creat, open, or _sopen.

If a bit in the mask is 1, the corresponding bit in the requested permission value of the file is set to 0 (disallowed). If a bit in the mask is 0, the corresponding bit is left unchanged. The permission setting for a new file is not set until the file is closed for the first time.

The possible values for pmode are defined in <sys\stat.h>:

Value | Meaning
S_IREAD | No effect
S_IWRITE | Writing not permitted
S_IREAD | S_IWRITE | Writing not permitted.

If the write bit is set in the mask, any new files will be read-only. You cannot give write-only permission, meaning that setting the read bit has no effect.

Note: In earlier releases of the C/C++ run-time library, umask began with an underscore (_umask). Because it is defined by the X/Open standard, the underscore has been removed. For compatibility, IBM C and C++ Compilers will map _umask to umask for you.

Return Value
umask returns the previous value of pmode. A return value of -1 indicates that the value used for pmode was not valid, and errno is set to EINVAL.

Example
This example sets the permission mask to create a write-only file.

    #include <sys\stat.h>
    #include <io.h>
    #include <stdio.h>

    int main(void)
    {
       int oldMask;

       oldMask = umask(S_IWRITE);
       printf("\nDefault system startup mask is %d.\n", oldMask);
       return 0;

       /*********************************************************
          The output should be:

          Default system startup mask is 0.
       *********************************************************/
    }

chmod -- Change File Permission Setting
creat -- Create New File
open -- Open File
_sopen -- Open Shared File
<io.h>
<sys\stat.h>