From 934d8d5ee4c2ce756fea79d74d8562ad597cc5e5 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Tue, 31 Dec 2024 16:09:27 +0100 Subject: stat: Use the standard values for S_ISDIR/S_ISREG etc --- include/sys/stat.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/include/sys/stat.h b/include/sys/stat.h index 42a2e95..9258ce7 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -4,13 +4,23 @@ #include #include -#define STAT_REG (1 << 0) -#define STAT_DIR (1 << 1) -#define STAT_FIFO (1 << 2) +#define S_IFMT 0170000 -#define S_ISREG(_v) (((_v) >> 0) & 1) -#define S_ISDIR(_v) (((_v) >> 1) & 1) -#define S_ISFIFO(_v) (((_v) >> 2) & 1) +#define S_IFDIR 0040000 +#define S_IFCHR 0020000 +#define S_IFBLK 0060000 +#define S_IFREG 0100000 +#define S_IFIFO 0010000 +#define S_IFLNK 0120000 +#define S_IFSOCK 0140000 + +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) +#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) +#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) +#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) struct stat { dev_t st_dev; // Device ID of device containing file. -- cgit v1.2.3