umask()--Set Authorization Mask for Job


  Syntax
 #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.


Parameters

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

Authorities

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

None.


Error Messages

The following messages may be sent from this function:

Message ID Error Message Text
CPE3418 E Possible APAR condition or hardware failure.
CPFA0D3 E cmask parameter is not valid.
CPFA0D4 E File system error occurred. Error number &1.
CPF3CF2 E Error(s) occurred during running of &1 API.
CPF9872 E Program or service program &1 in library &2 ended. Reason code &3.


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


Example

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>

main()
{
  int  file_descriptor;
  struct stat info;

  umask(S_IRWXG);

  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);
    close(file_descriptor);
    unlink("umask.file");
  }
}

Output:

permissions are: 000081c0


API introduced: V3R1

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