aboutsummaryrefslogtreecommitdiffstats
path: root/include/sys/stat.h
blob: dd60f92d4e2f390e75115fac19a368f97effa0db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/**
 * slibc — Yet another C library
 * Copyright © 2015, 2016  Mattias Andrée (maandree@member.fsf.org)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _SYS_STAT_H
#define _SYS_STAT_H
#include <slibc/version.h>
#include <slibc/features.h>



/**
 * Users that are not the owner and are int the
 * group (“others”) have read permission.
 * 
 * @since  Always.
 */
#define S_IROTH  4

/**
 * Users that are not the owner and are int the
 * group (“others”) have write permission.
 * 
 * @since  Always.
 */
#define S_IWOTH  2

/**
 * Users that are not the owner and are int the
 * group (“others”) have execute permission.
 * Execute permission for directories means to
 * be able to list files in the directory.
 * 
 * @since  Always.
 */
#define S_IXOTH  1

/**
 * Users that are not the owner and are int the
 * group (“others”) have all/some permissions.
 * 
 * This macro is defined to be equivalent to
 * `(S_IROTH | S_IWOTH | S_IXOTH)`.
 * 
 * @since  Always.
 */
#define S_IRWXO  (S_IROTH | S_IWOTH | S_IXOTH)


/**
 * Users that are in the group but is not the
 * owner have read permission.
 * 
 * @since  Always.
 */
#define S_IRGRP  (S_IROTH << 3)

/**
 * Users that are in the group but is not the
 * owner have write permission.
 * 
 * @since  Always.
 */
#define S_IWGRP  (S_IWOTH << 3)

/**
 * Users that are in the group but is not the
 * owner have execute permission.
 * Execute permission for directories means to
 * be able to list files in the directory.
 * 
 * @since  Always.
 */
#define S_IXGRP  (S_IXOTH << 3)

/**
 * Users that are in the group but is not the
 * owner have all/some permissions.
 * 
 * This macro is defined to be equivalent to
 * `(S_IRGRP | S_IWGRP | S_IXGRP)`.
 * 
 * @since  Always.
 */
#define S_IRWXG  (S_IRGRP | S_IWGRP | S_IXGRP)


/**
 * The owner (“user”) has read permission.
 * 
 * @since  Always.
 */
#define S_IRUSR  (S_IROTH << 6)

/**
 * The owner (“user”) has write permission.
 * 
 * @since  Always.
 */
#define S_IWUSR  (S_IWOTH << 6)

/**
 * The owner (“user”) has execute permission.
 * Execute permission for directories means to
 * be able to list files in the directory.
 * 
 * @since  Always.
 */
#define S_IXUSR  (S_IXOTH << 6)

/**
 * The owner (“user”) has all/some permissions.
 * 
 * This macro is defined to be equivalent to
 * `(S_IRUSR | S_IWUSR | S_IXUSR)`.
 * 
 * @since  Always.
 */
#define S_IRWXU  (S_IRUSR | S_IWUSR | S_IXUSR)


/**
 * Set user ID upon execution (setuid; set-user-ID)
 * is set.
 * 
 * For executable files, when a user runs the
 * program (must have sufficient privileges to
 * do so, here is however documentation that is
 * is not required, so perhaps it is not required
 * on all systems, but it is required on Linux)
 * her effective user ID is switched to that of
 * the owner of the file. Most systems disregard
 * this flag for interpreted files, and can be
 * made ineffective with mount options.
 * 
 * For directories, on some systems, when a new
 * file or subdirectory is created, it inherit
 * the user ID (owner) of the directory in which
 * it is created.
 * 
 * @since  Always.
 */
#define S_ISUID  (4 << 9)

/**
 * Set group ID upon execution (setgid; set-group-ID)
 * is set.
 * 
 * For executable files, when a user runs the
 * program (must have sufficient privileges to
 * do so, here is however documentation that is
 * is not required, so perhaps it is not required
 * on all systems, but it is required on Linux)
 * her effective group ID is switched to that of
 * the group of the file. Most systems disregard
 * this flag for interpreted files, and can be
 * made ineffective with mount options.
 * 
 * For directories, on some systems, when a new
 * file or subdirectory is created, it inherit
 * the group ID of the directory in which it is
 * created.
 * 
 * On Linux, if set-group-ID is set, but members
 * of the group do not have execute permission
 * (`S_IXGRP` is cleared), the file locks on the
 * file are mandatory.
 * 
 * @since  Always.
 */
#define S_ISGID  (2 << 9)

/**
 * Sticky bit (as it is called for regular files) or
 * restricted deletion flag (as it is called for
 * directories) is set.
 * 
 * If set, for directories, unprivileged users
 * cannot remove or rename a file in the directory.
 * They have to own the file or the directory.
 * Directories that anyone can write to, such as
 * '/tmp' and '/var/tmp' usually has this set.
 * 
 * If set, for regular files, it saves the
 * text image of a the program to the swap device,
 * so it will load more quickly when run. This
 * is only present on some older Unix systems.
 * 
 * @since  Always.
 */
#define S_ISVTX  (1 << 9)



#if defined(__SLIBC_SOURCE)
/**
 * Everyone, or anyone, have read permission.
 * 
 * This macro is defined to be equivalent to
 * `(S_IRUSR | S_IRGRP | S_IROTH)`.
 * 
 * This is a slibc extension.
 * 
 * @since  Always.
 */
# define S_IRALL  (S_IRUSR | S_IRGRP | S_IROTH)

/**
 * Everyone, or anyone, have write permission.
 * 
 * This macro is defined to be equivalent to
 * `(S_IWUSR | S_IWGRP | S_IWOTH)`.
 * 
 * This is a slibc extension.
 * 
 * @since  Always.
 */
# define S_IWALL  (S_IWUSR | S_IWGRP | S_IWOTH)

/**
 * Everyone, or anyone, have execute permission.
 * Execute permission for directories means to
 * be able to list files in the directory.
 * 
 * This macro is defined to be equivalent to
 * `(S_IXUSR | S_IXGRP | S_IXOTH)`.
 * 
 * This is a slibc extension.
 * 
 * @since  Always.
 */
# define S_IXALL  (S_IXUSR | S_IXGRP | S_IXOTH)

/**
 * Set-user-ID bit, set-group-ID bit, and/or sticky bit
 * is set.
 * 
 * This macro is defined to be equivalent to
 * `(S_ISUID | S_ISGID | S_ISVTX)`.
 * 
 * This is a slibc extension.
 * 
 * @since  Always.
 */
# define S_ISALL  (S_ISUID | S_ISGID | S_ISVTX)
#endif



#endif