umask()--Set Authorization Mask for Job

 #include <sys/stat.h>

 mode_t umask(mode_t cmask);  
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

  Threadsafe: Yes

Every job has a file creation mask. When a job starts, the value of the file creation mask is zero. The value of zero means that no permissions are masked when a file or directory is created in the job. The umask() function changes the value of the file creation mask for the current job to the value specified in cmask.

The cmask argument controls file permission bits that should be set whenever the job creates a file. File permission bits set to 1 in the file creation mask are set to 0 in the file permission bits of files that are created by the job.

For example, if a call to open() specifies a mode argument with file permission bits, the file creation mask of the job affects the mode argument; bits that are 1 in the mask are set to 0 in the mode argument and, therefore, in the mode of the created file.

Only the file permission bits of cmask are used. The other bits in cmask must be cleared (not set), or the CPFA0D3 message is issued.


(Input) The new value of the file creation mask. For a description of the permission bits, see chmod()--Change File Authorizations.


No authorization is required.

Return Value

umask() returns the previous value of the file creation mask. It does not return -1 or set the errno global variable.

Error Conditions


Error Messages

The following messages may be sent from this function:

Usage Notes

  1. QNTC File System Differences

    umask() does not update the file creation mask for QNTC. The settings specified in cmask are ignored.

Related Information


The following example uses umask().

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>

  int  file_descriptor;
  struct stat info;


  if ((file_descriptor =
       creat("umask.file", S_IRWXU|S_IRWXG)) < 0)
     perror("creat() error");
  else {
    fstat(file_descriptor, &info);
    printf("permissions are: %08x\n", info.st_mode);


permissions are: 000081c0

API introduced: V3R1

[ Back to top | UNIX-Type APIs | APIs by category ]