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 );

Since:

BlackBerry 10.0.0

Arguments:

cmask
The new file-mode creation mask; that is, the permissions that you don't want set when the process creates a file. The mask is a combination of these bits:
Owner Group Others Permission
S_IRUSR S_IRGRP S_IROTH Read
S_IRWXU S_IRWXG S_IRWXO Read, write, execute/search; a bitwise inclusive OR of the other three constants. (S_IRWXU is OR of IRUSR, S_IWSUR and S_IXUSR.)
S_IWUSR S_IWGRP S_IWOTH Write
S_IXUSR S_IXGRP S_IXOTH Execute/search

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

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.

In order to change the mask for a process with a different effective user ID, your process must have the PROCMGR_AID_UMASK ability enabled. For more information, see procmgr_ability().

The file-mode creation mask for the process is used when you call creat(), mkdir(), mkfifo(), and open(), 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 <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>

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

Classification:

POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus