Chapter Contents |
Previous |
Next |
umask |
Portability: | POSIX.1 conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
EXAMPLE | |
RELATED FUNCTIONS |
SYNOPSIS |
#include <sys/stat.h> #include <sys/types.h> mode_t umask(mode_t creationMask);
DESCRIPTION |
umask
changes the file mode creation mask to the value specified by
creationMask
. The file mode creation
mask controls which permission bits may be set when a file is created. Bits
that are set to 1 in the file mode creation mask are used to mask the corresponding
permission bits when a file is created. For example, setting the file group
read permission bit,
S_IRGRP
,
in the file mode creation mask will prevent this bit from being set when a
new file is created.
The value of
creationMask
is formed by ORing any of the following symbols, which
are defined in the
<stat.h>
include file:
RETURN VALUE |
umask
always returns the previously defined file mode creation mask.
There is no way to read the value of the creation mask without changing it.
It requires two calls to
umask
to determine the value of the mask: first you read the original value,
then you reset the mask to the original value.
EXAMPLE |
The following code fragment illustrates
the use of
umask
to change
the file mode creation mask:
#include <sys/types.h> #include <sys/stat.h> #include <stdio.h> main() mode_t oldMask, newMask; /* Get old mask, temporarily setting the mask to 0. */ oldMask = umask((mode_t) 0); /* Print old mask. Octal values are used by mask. */ printf("Old mask = %on", (int) oldMask); /* Make sure group read permission is allowed. */ if (oldMask & S_IRGRP) { printf("Changing group read permission from MASKED to UNMASKED.n"); oldMask = (oldMask ^ S_IRGRP); } /* Make sure group write and execute permission is not allowed. */ newMask = (oldMask|S_IWGRP|S_IXGRP); umask(newMask); /* Update mask. */ printf("New mask = %onn", (int) newMask); /* Print new mask. */ printf("The file mode creation mask now specifies:nn"); printf(" Group read permission UNMASKEDn"); printf(" Group write permission MASKEDn"); printf(" Group execute permission MASKEDn"); }
RELATED FUNCTIONS |
ccreat
,
mkdir
,
mkfifo
,
mknod
,
open
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.