Skip to content

Commit c618e13

Browse files
authored
[libc] Pull more definitions from linux/stat.h (llvm#67071)
For file handling, we need more definitions from linux/stat.h, so this pulls them in. It also adjusts other definitions to match the kernel's exactly [NFC] so that it's easy to verify that there's been no divergence one day when it's time to use linux/stat.h directly. Tested: check-libc
1 parent f90e063 commit c618e13

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

libc/include/llvm-libc-macros/linux/sys-stat-macros.h

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,40 @@
99
#ifndef __LLVM_LIBC_MACROS_LINUX_SYS_STAT_MACROS_H
1010
#define __LLVM_LIBC_MACROS_LINUX_SYS_STAT_MACROS_H
1111

12-
// File mode flags
13-
#define S_IRWXU 0700
14-
#define S_IRUSR 0400
15-
#define S_IWUSR 0200
16-
#define S_IXUSR 0100
17-
#define S_IRWXG 070
18-
#define S_IRGRP 040
19-
#define S_IWGRP 020
20-
#define S_IXGRP 010
21-
#define S_IRWXO 07
22-
#define S_IROTH 04
23-
#define S_IWOTH 02
24-
#define S_IXOTH 01
25-
#define S_ISUID 04000
26-
#define S_ISGID 02000
12+
// Definitions from linux/stat.h
13+
#define S_IFMT 00170000
14+
#define S_IFSOCK 0140000
15+
#define S_IFLNK 0120000
16+
#define S_IFREG 0100000
17+
#define S_IFBLK 0060000
18+
#define S_IFDIR 0040000
19+
#define S_IFCHR 0020000
20+
#define S_IFIFO 0010000
21+
#define S_ISUID 0004000
22+
#define S_ISGID 0002000
23+
#define S_ISVTX 0001000
24+
25+
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
26+
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
27+
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
28+
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
29+
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
30+
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
31+
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
32+
33+
#define S_IRWXU 00700
34+
#define S_IRUSR 00400
35+
#define S_IWUSR 00200
36+
#define S_IXUSR 00100
37+
38+
#define S_IRWXG 00070
39+
#define S_IRGRP 00040
40+
#define S_IWGRP 00020
41+
#define S_IXGRP 00010
42+
43+
#define S_IRWXO 00007
44+
#define S_IROTH 00004
45+
#define S_IWOTH 00002
46+
#define S_IXOTH 00001
2747

2848
#endif // __LLVM_LIBC_MACROS_LINUX_SYS_STAT_MACROS_H

0 commit comments

Comments
 (0)