#include <sys/types.h> #include <sys/stat.h>
int stat(path, buf) char *path; struct stat *buf;
int lstat(path, buf) char *path; struct stat *buf;
int fstat(fd, buf) int fd; struct stat *buf;
stat() obtains information about the file named by path. Read, write or execute permission of the named file is not required, but all directories listed in the path name leading to the file must be searchable.
lstat() is like stat() except in the case where the named file is a symbolic link, in which case lstat() returns information about the link, while stat() returns information about the file the link references.
fstat() obtains the same information about an open file referenced by the argument descriptor, such as would be obtained by an open.2v call.
buf is a pointer to a stat structure into which information is placed concerning the file. A stat structure includes the following members:
dev_t st_dev; /* device file resides on */ ino_t st_ino; /* the file serial number */ mode_t st_mode; /* file mode */ nlink_t st_nlink; /* number of hard links to the file */ uid_t st_uid; /* user ID of owner */ gid_t st_gid; /* group ID of owner */ dev_t st_rdev; /* the device identifier (special files only)*/ off_t st_size; /* total size of file, in bytes */ time_t st_atime; /* file last access time */ time_t st_mtime; /* file last modify time */ time_t st_ctime; /* file last status change time */ long st_blksize; /* preferred blocksize for file system I/O*/ long st_blocks; /* actual number of blocks allocated */
The following macros test whether a file is of the specified type. The value m is the value of st_mode. Each macro evaluates to a non-zero value if the test is true or to zero if the test is false.
The status information word st_mode is bit-encoded using the following masks and bits:
In addition, the following bits and masks are made available for backward compatibility:
#define S_IFMT 0170000 /* type of file */ #define S_IFIFO 0010000 /* FIFO special */ #define S_IFCHR 0020000 /* character special */ #define S_IFDIR 0040000 /* directory */ #define S_IFBLK 0060000 /* block special */ #define S_IFREG 0100000 /* regular file */ #define S_IFLNK 0120000 /* symbolic link */ #define S_IFSOCK 0140000 /* socket */ #define S_ISVTX 0001000 /* save swapped text even after use */ #define S_IREAD 0000400 /* read permission, owner */ #define S_IWRITE 0000200 /* write permission, owner */ #define S_IEXEC 0000100 /* execute/search permission, owner */
For more information on st_mode bits see chmod.2v
stat(), lstat() and fstat() return:
stat() and lstat() will fail if one or more of the following are true:
A pathname component is longer than {NAME_MAX} while {_POSIX_NO_TRUNC} is in effect (see pathconf.2v
fstat() will fail if one or more of the following are true:
In addition to the above, the following may also occur:
The st_atime and st_mtime fields of the stat() are not contiguous. Programs that depend on them being contiguous (in calls to utimes.2 or utime.3v will not work.
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97