Sets the default file-permission mask.
#include <sys\types.h> | ||
#include <sys\stat.h> | ||
#include <io.h> | Required only for function declarations |
int _umask( int pmode );
pmode | Default permission setting |
The _umask function sets the file-permission mask of the current process to the mode specified by pmode. The file-permission mask is used to modify the permission setting of new files created by _creat, _open, or _sopen. If a bit in the mask is 1, the corresponding bit in the file's requested permission value is set to 0 (disallowed). If a bit in the mask is 0, the corresponding bit is left unchanged. The permission setting for a new file is not set until the file is closed for the first time.
The argument pmode is a constant expression containing one or both of the manifest constants _S_IREAD and _S_IWRITE, defined in SYS\STAT.H. When both constants are given, they are joined with the bitwise-OR operator (|). The meaning of the pmode argument is as follows:
Value | Meaning |
_S_IREAD | Reading not allowed (file is write-only) |
_S_IWRITE | Writing not allowed (file is read-only) |
For example, if the write bit is set in the mask, any new files will be read-only.
Note that with DOS, all files are readable—it is not possible to give write-only permission. Therefore, setting the read bit with _umask has no effect on the file's modes.
The _umask function returns the previous value of pmode. There is no error return.
Standards:UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
Use _umask for compatibility with ANSI naming conventions of non-ANSI functions. Use umask and link with OLDNAMES.LIB for UNIX compatibility.
/* UMASK.C: This program uses _umask to set the file-permission mask so
* that all future files will be created as read-only files. It also
* displays the old mask.
*/
#include <sys\types.h>
#include <sys\stat.h>
#include <io.h>
#include <stdio.h>
void main( void )
{
int oldmask;
/* Create read-only files: */
oldmask = _umask( _S_IWRITE );
printf( “Oldmask = 0x%.4x\n”, oldmask );
}
Oldmask = 0x0000