FileSys::Stat()

Obtain information about the file specified by the path protected FileSys member.

Virtual?

Yes

 

Class

FileSys

 

Arguments

None

 

Returns

int

0 for failure, or status bits as defined below

The status bits have the following meanings:

Status Meaning

0

failure

FSF_EXISTS (0x01)

file exists

FSF_WRITEABLE (0x02)

file is user-writable

FSF_DIRECTORY (0x04)

file is a directory

FSF_SYMLINK (0x08)

file is symlink

FSF_SPECIAL (0x10)

file is a special file (in the UNIX sense)

FSF_EXECUTABLE (0x20)

file is executable

FSF_EMPTY (0x40)

file is empty

FSF_HIDDEN (0x80)

file is invisible (hidden)

Notes

The default implementation of Stat() is called to obtain file status every time a file is opened for read.

Example

To use Stat() to verify the existence of /usr/bin/p4:

FileSys *f = FileSys::Create( FST_BINARY );
f->Set( "/usr/bin/p4" );
int state = f->Stat();

if ( state & FSF_EXISTS )
    printf( "File found\n" );

To reimplement Stat() to provide debugging output:

int FileSysDemo::Stat()
{
    int flags = 0;
    struct stat st;

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

    if ( stat( Name(), &st ) < 0 )
        return( flags );

    // Set internal flags

    flags |= FSF_EXISTS;

    if ( st.st_mode & S_IWUSR ) flags |= FSF_WRITEABLE;
    if ( st.st_mode & S_IXUSR ) flags |= FSF_EXECUTABLE;
    if ( S_ISDIR( st.st_mode ) ) flags |= FSF_DIRECTORY;
    if ( !S_ISREG( st.st_mode ) ) flags |= FSF_SPECIAL;
    if ( !st.st_size ) flags |= FSF_EMPTY;
    return flags;
}