STAT(2)
NAME
stat, lstat, fstat − get file status
SYNOPSIS
#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 (fildes, buf)
int fildes;
struct stat ∗buf;
HP-UX COMPATIBILITY
Level:
Stat and fstat: HP-UX/RUN ONLY
Lstat: HP-UX/EXTENDED
Origin:
System V
DESCRIPTION
Path points to a path name naming a file. 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. Stat obtains information about the named file.
Similarly, fstat obtains information about an open file known by the file descriptor fildes, obtained from a successful open, creat, dup, fcntl, or pipe system call.
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. Not all HP-UX systems provide symbolic links.
Buf is a pointer to a stat structure into which information is placed concerning the file.
The contents of the structure pointed to by buf include the following members:
dev_tst_dev;/* ID of device containing a */
/* directory entry for this file */
ino_tst_ino;/* Inode number */
ushortst_mode;/* File mode; see mknod(2) */
shortst_nlink;/* Number of links */
ushortst_uid;/* User ID of file owner */
ushortst_gid;/* Group ID of file group */
dev_tst_rdev;/* Device ID; this entry defined */
/* only for char or blk spec files */
off_tst_size;/* File size (bytes) */
time_tst_atime;/* Time of last access */
time_tst_mtime;/* Last modification time */
time_tst_ctime;/* Last file status change time */
/* Measured in secs since */
/* 00:00:00 GMT, Jan 1, 1970 */
st_atime Time when file data was last accessed. Changed by the following system calls: creat(2), mknod(2), pipe(2), utime(2), and read(2).
st_mtime
Time when data was last modified. Changed by the following system calls: creat(2), mknod(2), pipe(2), utime(2), and write(2).
st_ctime Time when file status was last changed. Changed by the following system calls: chmod(2), chown(2), creat(2), link(2), mknod(2), pipe(2), unlink(2), utime(2), and write(2).
The touch(1) command can be used to explicitly control the times of a file.
Stat will fail if one or more of the following are true:
[ENOTDIR] A component of the path prefix is not a directory.
[ENOENT] The named file does not exist.
[EACCES] Search permission is denied for a component of the path prefix.
[EFAULT] Buf or path points to an invalid address.
[ENOENT] Path is null.
Fstat will fail if one or more of the following are true:
[EBADF] Fildes is not a valid open file descriptor.
[EFAULT] Buf points to an invalid address.
RETURN VALUE
Upon successful completion a value of 0 is returned. Otherwise, a value of −1 is returned and errno is set to indicate the error.
HARDWARE DEPENDENCIES
Integral PC:
The bstat and bfstat calls are identical to stat and fstat except that the st_dev and st_rdev fields in the bstat structure are larger than the st_dev and st_rdev fields in the stat structure. Bstat and bfstat are used in place of stat and fstat on HP-UX implementations with long device numbers (such as the Integral PC). This difference is relevant only to applications which examine the st_dev or st_rdev fields of the stat (bstat) structure.
int bstat (path, buf)
char *path;
struct bstat *buf;
int bstat (fildes, buf)
int fildes;
struct bstat *buf;
Series 200 and 500:
Symbolic links are not supported on Series 200 and Series 500 computers.
SEE ALSO
touch(1), chmod(2), chown(2), creat(2), link(2), mknod(2), pipe(2), read(2), time(2), unlink(2), utime(2), write(2), stat(7).
Hewlett-Packard — last mod. May 11, 2021