diff --git a/include/dirent.h b/include/dirent.h index 99773ac..f2bb73e 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -9,8 +9,13 @@ extern "C" { #include #define DT_UNKNOWN 0 /* Unknown type */ -#define DT_REG 1 /* Regular file */ -#define DT_DIR 2 /* Directory */ +#define DT_BLK 1 /* Block device */ +#define DT_CHR 2 /* Character device */ +#define DT_DIR 3 /* Directory */ +#define DT_FIFO 4 /* FIFO */ +#define DT_LNK 5 /* Symbolic link */ +#define DT_REG 6 /* Regular file */ +#define DT_SOCK 7 /* Socket */ /* In gint d_ino is unused; but it's required by POSIX.1. */ struct dirent { diff --git a/include/sys/stat.h b/include/sys/stat.h index b8ca1bb..4a3b886 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -5,41 +5,75 @@ extern "C" { #endif -/* File types. */ -#define __S_IFMT 0170000 /* These bits determine file type. */ -#define __S_IFDIR 0040000 /* Directory. */ -#define __S_IFCHR 0020000 /* Character device. */ -#define __S_IFBLK 0060000 /* Block device. */ -#define __S_IFREG 0100000 /* Regular file. */ -#define __S_IFIFO 0010000 /* FIFO. */ -#define __S_IFLNK 0120000 /* Symbolic link. */ -#define __S_IFSOCK 0140000 /* Socket. */ +#include +#include -/* Protection bits. */ -#define __S_ISUID 0004000 /* Set user ID on execution. */ -#define __S_ISGID 0002000 /* Set group ID on execution. */ -#define __S_ISVTX 0001000 /* Save swapped text after use (sticky). */ -#define __S_IREAD 0000400 /* Read by owner. */ -#define __S_IWRITE 0000200 /* Write by owner. */ -#define __S_IEXEC 0000100 /* Execute by owner. */ +/* 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 */ -#define S_IRUSR __S_IREAD /* Read by owner. */ -#define S_IWUSR __S_IWRITE /* Write by owner. */ -#define S_IXUSR __S_IEXEC /* Execute by owner. */ -/* Read, write, and execute by owner. */ -#define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC) +/* 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) -#define S_IRGRP (S_IRUSR >> 3) /* Read by group. */ -#define S_IWGRP (S_IWUSR >> 3) /* Write by group. */ -#define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */ -/* Read, write, and execute by group. */ -#define S_IRWXG (S_IRWXU >> 3) +/* 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 -#define S_IROTH (S_IRGRP >> 3) /* Read by others. */ -#define S_IWOTH (S_IWGRP >> 3) /* Write by others. */ -#define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */ -/* Read, write, and execute by others. */ -#define S_IRWXO (S_IRWXG >> 3) +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_link; + 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); #ifdef __cplusplus } diff --git a/include/sys/types.h b/include/sys/types.h index 25c39eb..a7f6f95 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -8,25 +8,39 @@ extern "C" { #include #include -// Define properly off_t type. -# ifndef __off_t_defined -typedef int32_t off_t; -# define __off_t_defined -# endif +/* Number of blocks in a file */ +typedef uint16_t blkcnt_t; -// Define properly ssize_t type. -#ifndef __ssize_t_defined -typedef int32_t ssize_t; -# define __ssize_t_defined -#endif +/* Size of a file block */ +typedef uint16_t blksize_t; -// Define alias -typedef int32_t pid_t; -typedef int16_t mode_t; +/* Device identifier, with a major and minor byte */ typedef uint16_t dev_t; -typedef uint16_t umode_t; + +/* Type of group identifiers on the system */ +typedef uint16_t gid_t; + +/* Inode number */ typedef uint32_t ino_t; +/* Holds a file's type and permissions bits */ +typedef int16_t mode_t; + +/* Number of hard links to a file */ +typedef uint16_t nlink_t; + +/* Offset within a file or stream; also, file size */ +typedef int32_t off_t; + +/* Process identifier */ +typedef int16_t pid_t; + +/* Signed size_t which can hold the value -1 */ +typedef int32_t ssize_t; + +/* Type of user identifiers on the system */ +typedef uint16_t uid_t; + #ifdef __cplusplus } #endif