FileSys::Stat()
Obtain information about the file specified by the path
protected FileSys member.
|
Virtual? |
Yes |
|
|
Class |
||
|
Arguments |
None |
|
|
Returns |
|
0 for failure, or status bits as defined below |
The status bits have the following meanings:
| Status | Meaning |
|---|---|
|
|
failure |
|
|
file exists |
|
|
file is user-writable |
|
|
file is a directory |
|
|
file is symlink |
|
|
file is a special file (in the UNIX sense) |
|
|
file is executable |
|
|
file is empty |
|
|
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;
}






