Borland C++ reference

umask

raw OCR

Sets file read/write permission mask.

Defined in header <io.h>

Syntax

#include <io.h>
unsigned umask(unsigned   mode);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

The umask function sets the access permission mask used by open and creat. Bits that are set in mode will be cleared in the access permission of files subsequently created by open and creat.

The mode can have one of the following values, defined in sys\ stat.h:

Value of modeAccess permission
S_IWRITEPermission to write
SJREADPermission to read
S IREADIS IWRITEPermission to read and write

Return value

The previous value of the mask. There is no error return.

See also

Example

include  <io.h>
iinclude <stdio.h>
#include <sys\stat.h>

#define FILENAME  "TEST.$$$"

int main (void)
{
    unsigned oldmask;
    FILE *f;
    struct Stat statbuf;
    /* Cause subsequent  files to be created as read-only */
    oldmask = umask (S_IWRITE);
    printf("Old mask -  Ox%x\n",oldmask);

    /* Create a zero-length  file */
    if ((f = fopen(FILENAME,"w"))  == NULL) {
        perror("Unable to create  output file");
        return  (1);
    }
fclose (f);

/* Verify that the file  is read-only */
if (Stat (FILENAME,&statbuf) != 0) {
    perror("Unable to get  information about output file");
    return  (1) ;
}
if (statbuf.st_mode & S_IWRITE)
    printf ("Error! %s is writable!\n",FILENAME);
else
    printf ("Success! %s is not writable.\n",FILENAME);
return (0);

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.