_umask

Sets the default file-permission mask.

int_umask(intpmode**);**

Routine Required Header Compatibility
_umask <io.h> and <sys/stat.h> and <sys/types.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

_umask returns the previous value of pmode. There is no error return.

Parameter

pmode

Default permission setting

Remarks

The _umask function sets the file-permission mask of the current process to the mode specified by pmode. The file-permission mask modifies 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 ( | ). If the pmode argument is _S_IREAD, reading is not allowed (the file is write-only). If the pmode argument is _S_IWRITE, writing is not allowed (the 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 MS-DOS, Windows NT, and Windows 95, 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.

Example

/* 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/stat.h>
#include <sys/types.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 );
}

Output

Oldmask = 0x0000

File Handling RoutinesLow-level I/O Routines

See Also   _chmod, _creat, _mkdir, _open