-
Difference between revisions of "Functions HI-TECH C STAT"
(Created page with "<strong>STAT</strong> ==SYNOPSIS== #include <stat.h> int stat(char * name, struct stat * statbuf) ==DESCRIPTION== This routine returns information about the file...") |
(No difference)
|
Revision as of 23:58, 31 July 2017
STAT
SYNOPSIS
#include <stat.h> int stat(char * name, struct stat * statbuf)
DESCRIPTION
This routine returns information about the file by name. The information returned is operating system dependent, but may include file attributes (e.g. read only), file size in bytes, and file modification and/or access times. The argument name should be the name of the file, and may include path names under DOS, user numbers under CP/M, etc. The argument statbuf should be the address of a structure as defined in stat.h which will be filled in with the information about the file. The structure of struct stat is as follows:
struct stat { short st_mode; /* flags */ long st_atime; /* access time */ long st_mtime; /* modification time */ long st_size; /* file size */ };
The access and modification times (under DOS these
are both set to the modification time) are in
seconds since 00:00:00 Jan 1 1970. The function
ctime() may be used to convert this to a readable
value. The file size is self explanatory. The
flag bits are as follows:
Flag | Meaning | S_IFMT | mask for file type |
---|---|---|---|
S_IFDIR | file is a directory | ||
S_IFREG | file is a regular file | ||
S_IREAD | file is readable | ||
S_IWRITE | file is writeable | ||
S_IEXEC | file is executable | ||
S_HIDDEN | file is hidden | ||
S_SYSTEM | file is marked system | ||
S_ARCHIVE | file has been written to |
Stat returns 0 on success, -1 on failure, e.g. if
the file could not be found.
SEE ALSO
ctime, creat, chmod