umask Subroutine

Purpose

Sets and gets the value of the file creation mask.

Library

Standard C Library (libc.a)

Syntax

#include <sys/stat.h>

mode_t umask ( CreationMask)
mode_t CreationMask;

Description

The umask subroutine sets the file-mode creation mask of the process to the value of the CreationMask parameter and returns the previous value of the mask.

Whenever a file is created (by the open, mkdir, or mknod subroutine), all file permission bits set in the file mode creation mask are cleared in the mode of the created file. This clearing allows users to restrict the default access to their files.

The mask is inherited by child processes.

Parameters

Item Description
CreationMask Specifies the value of the file mode creation mask. The CreationMask parameter is constructed by logically ORing file permission bits defined in the sys/mode.h file. Nine bits of the CreationMask parameter are significant.

Return Values

If successful, the file permission bits returned by the umask subroutine are the previous value of the file-mode creation mask. The CreationMask parameter can be set to this value in subsequent calls to the umask subroutine, returning the mask to its initial state.