#ifndef __SYS_STAT_H__ # define __SYS_STAT_H__ #ifdef __cplusplus extern "C" { #endif #include #include /* File types; taken from inode(7), any values would probably work. */ #define S_IFMT 0170000 #define S_IFIFO 0010000 /* FIFO */ #define S_IFCHR 0020000 /* Character device */ #define S_IFDIR 0040000 /* Directory */ #define S_IFBLK 0060000 /* Block device */ #define S_IFREG 0100000 /* Regular file */ #define S_IFLNK 0120000 /* Symbolic link */ #define S_IFSOCK 0140000 /* Socket */ /* Shortcuts to check file types from a mode_t value */ #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) /* Protection bits of a mode_t */ #define S_ISUID 0004000 /* Set user ID on execution */ #define S_ISGID 0002000 /* Set group ID on execution */ #define S_ISVTX 0001000 /* Sticky bit */ /* Usual permissions */ #define S_IRWXU 00700 #define S_IRUSR 00400 #define S_IWUSR 00200 #define S_IXUSR 00100 #define S_IRWXG 00070 #define S_IRGRP 00040 #define S_IWGRP 00020 #define S_IXGRP 00010 #define S_IRWXO 00007 #define S_IROTH 00004 #define S_IWOTH 00002 #define S_IXOTH 00001 struct stat { off_t st_size; mode_t st_mode; /* In gint, the struct stat only has the file size and file type. The protection bits of (st_mode) are always 00777. The following fields all have undefined values. */ dev_t st_dev; ino_t st_ino; nlink_t st_nlink; uid_t st_uid; gid_t st_gid; dev_t st_rdev; blksize_t st_blksize; blkcnt_t st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; }; #define st_atime st_atim.tv_sec #define st_mtime st_mtim.tv_sec #define st_ctime st_ctim.tv_sec /* Obtain information about an entry in the filesystem. */ extern int stat(char const * __restrict__ __pathname, struct stat * __restrict__ __statbuf); extern int chmod(char const *__pathname, mode_t mode); extern int fstat(int __fd, struct stat *__buf); #ifdef __cplusplus } #endif #endif /*__SYS_STAT_H__*/