FAT | RFS | XFS | ZFS

rstat()

PROTOTYPE

#include <posix.h>

int rstat(const char *path, struct stat *info);

DESCRIPTION

rstat() is a non-standard routine that writes information about the file specified by path to the stat structure indicated by info. Paths starting with ‘/’ are absolute. Otherwise they are relative to the CWD. The stat structure is defined in “posix.h” and reproduced below:

struct stat
{
  dev_t   st_dev;    /* ID of device containing this file */
  ino_t   st_ino;    /* file serial number */
  nlink_t st_nlink;  /* number of links */
  dev_t   st_rdev;   /* device ID (if inode device) */
  off_t   st_size;   /* the file size in bytes */
  time_t  st_atime;  /* last data access time (secs since Epoch) */
  time_t  st_mtime;  /* last data modification time (secs since Epoch) */
  time_t  st_ctime;  /* last status change time (secs since Epoch) */
  mode_t  st_mode;   /* file mode */
  uid_t   st_uid;    /* user ID of file's owner */
  gid_t   st_gid;    /* group ID of file's owner */
};

“posix.h” defines macros that can be applied to the st_mode field to determine the file’s access permissions and mode. The S_ISDIR() and S_ISREG() macros test whether the file is a directory or regular file.

rstat() behaves like stat() except if the file is a directory, then the st_size field - instead of being set to zero - is the sum of the size of every regular file in the directory and its subdirectories. Because of the recursive size calculation, rstat() takes longer to execute than stat().

If successful, rstat() returns 0. Otherwise, it sets errno and returns -1.

ERROR CODES

EACCES No execute access to a directory in the path prefix.
EFAULT info or path equals NULL.
ENAMETOOLONG A name in path exceeds the effective maximum file name length.
ENOENT path is the empty string or includes a file that was not found.
ENOTDIR One of the non-leaf path components is not a directory.