Functions HI-TECH C STAT

From HI-TECH C for CP/M Fan WIKI(EN)
Jump to: navigation, search



#include  <stat.h>

int stat(char * name, struct stat * statbuf)


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.


ctime, creat, chmod