[Previous]
[Contents]
[Next]

umask()

set the file mode creation mask for the process

Synopsis:

#include <sys/types.h>
#include <sys/stat.h>
mode_t umask( mode_t cmask );

Description:

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 - see the Header Files chapter.

The file mode creation mask for the process is used during open(), creat(), mkdir(), and mkfifo() calls to turn off permission bits in the mode argument supplied. Bit positions set in cmask are cleared in the mode of the created file.

Returns:

The previous value of the file mode creation mask.

Examples:

/*
 * Set the umask to RW for owner,group; R for other
 */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

void main()
  {
    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 );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

chmod(), creat(), mkdir(), mkfifo(), open()


[Previous]
[Contents]
[Next]