FileSys::Chmod( FilePerm, Error * )

Modify the file mode bits of the file specified by the path protected FileSys member.

Virtual?

Yes

 

Class

FileSys

 

Arguments

FilePerm perms

permissions to change the file, either FPM_RO (read only) or FPM_RW (read/write)

 

Error *error

returned error status

Returns

void

 

Notes

This method is called to make a client file writable (FPM_RW) when it is opened for edit, or to change it to read-only (FPM_RO) after a submit.

A FilePerm is an enum taking one of the following values:

Argument Value Meaning

FPM_RO

0x00

leave file read-only.

FPM_RW

0x01

allow read and write operations

Example

To use Chmod() to create a configuration file and set its permissions to read-only:

FileSys *f = FileSys::Create( FST_ATEXT );
Error e;

f->Set( "c:\\configfile.txt" );
f->Chmod( FPM_RO, &e );

To reimplement Chmod() under UNIX:

void FileSysDemo::Chmod( FilePerm perms, Error *e )
{
    int bits = IsExec() ? PERM_0777 : PERM_0666;

    if ( perms == FPM_RO )
        bits &= ~PERM_0222;

    if ( chmod( Name(), bits & ~myumask ) < 0 )
        e->Sys( "chmod", Name() );

    if ( DEBUG )
        printf( "Debug (Chmod): %s\n", Name() );
}