]>
Commit | Line | Data |
---|---|---|
c67e25b4 | 1 | /* Copyright (C) 1991,1992,1995-2002,2003 Free Software Foundation, Inc. |
2c6fe0bd | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
2c6fe0bd | 4 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
28f540f4 | 8 | |
2c6fe0bd UD |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
28f540f4 | 13 | |
41bdb6e2 AJ |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, write to the Free | |
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
17 | 02111-1307 USA. */ | |
28f540f4 RM |
18 | |
19 | /* | |
20 | * POSIX Standard: 5.6 File Characteristics <sys/stat.h> | |
21 | */ | |
22 | ||
23 | #ifndef _SYS_STAT_H | |
28f540f4 | 24 | #define _SYS_STAT_H 1 |
5107cf1d | 25 | |
28f540f4 RM |
26 | #include <features.h> |
27 | ||
5107cf1d | 28 | #include <bits/types.h> /* For __mode_t and __dev_t. */ |
28f540f4 | 29 | |
c67e25b4 AJ |
30 | #if defined __USE_XOPEN || defined __USE_MISC |
31 | # ifdef __USE_XOPEN | |
32 | # define __need_time_t | |
33 | # endif | |
8cac677c UD |
34 | # ifdef __USE_MISC |
35 | # define __need_timespec | |
36 | # endif | |
c67e25b4 AJ |
37 | # include <time.h> /* For time_t resp. timespec. */ |
38 | #endif | |
6077fe6e | 39 | |
c67e25b4 | 40 | #ifdef __USE_XOPEN |
9756dfe1 UD |
41 | /* The Single Unix specification says that some more types are |
42 | available here. */ | |
7df789e0 | 43 | # ifndef __dev_t_defined |
9756dfe1 | 44 | typedef __dev_t dev_t; |
7df789e0 | 45 | # define __dev_t_defined |
9756dfe1 UD |
46 | # endif |
47 | ||
7df789e0 | 48 | # ifndef __gid_t_defined |
9756dfe1 | 49 | typedef __gid_t gid_t; |
7df789e0 | 50 | # define __gid_t_defined |
9756dfe1 UD |
51 | # endif |
52 | ||
7df789e0 | 53 | # ifndef __ino_t_defined |
9756dfe1 UD |
54 | # ifndef __USE_FILE_OFFSET64 |
55 | typedef __ino_t ino_t; | |
56 | # else | |
57 | typedef __ino64_t ino_t; | |
58 | # endif | |
7df789e0 | 59 | # define __ino_t_defined |
9756dfe1 UD |
60 | # endif |
61 | ||
7df789e0 | 62 | # ifndef __mode_t_defined |
9756dfe1 | 63 | typedef __mode_t mode_t; |
7df789e0 | 64 | # define __mode_t_defined |
9756dfe1 UD |
65 | # endif |
66 | ||
7df789e0 | 67 | # ifndef __nlink_t_defined |
9756dfe1 | 68 | typedef __nlink_t nlink_t; |
7df789e0 | 69 | # define __nlink_t_defined |
9756dfe1 UD |
70 | # endif |
71 | ||
7df789e0 | 72 | # ifndef __off_t_defined |
9756dfe1 UD |
73 | # ifndef __USE_FILE_OFFSET64 |
74 | typedef __off_t off_t; | |
75 | # else | |
76 | typedef __off64_t off_t; | |
77 | # endif | |
7df789e0 | 78 | # define __off_t_defined |
9756dfe1 UD |
79 | # endif |
80 | ||
7df789e0 | 81 | # ifndef __uid_t_defined |
9756dfe1 | 82 | typedef __uid_t uid_t; |
7df789e0 | 83 | # define __uid_t_defined |
9756dfe1 | 84 | # endif |
6077fe6e | 85 | #endif /* X/Open */ |
9756dfe1 | 86 | |
6077fe6e | 87 | #ifdef __USE_UNIX98 |
219aa9e9 UD |
88 | # ifndef __blkcnt_t_defined |
89 | # ifndef __USE_FILE_OFFSET64 | |
90 | typedef __blkcnt_t blkcnt_t; | |
91 | # else | |
92 | typedef __blkcnt64_t blkcnt_t; | |
93 | # endif | |
94 | # define __blkcnt_t_defined | |
95 | # endif | |
96 | ||
97 | # ifndef __blksize_t_defined | |
98 | typedef __blksize_t blksize_t; | |
99 | # define __blksize_t_defined | |
9756dfe1 UD |
100 | # endif |
101 | #endif /* Unix98 */ | |
102 | ||
28f540f4 RM |
103 | __BEGIN_DECLS |
104 | ||
5107cf1d | 105 | #include <bits/stat.h> |
28f540f4 | 106 | |
6077fe6e | 107 | #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN |
dfd2257a UD |
108 | # define S_IFMT __S_IFMT |
109 | # define S_IFDIR __S_IFDIR | |
110 | # define S_IFCHR __S_IFCHR | |
111 | # define S_IFBLK __S_IFBLK | |
112 | # define S_IFREG __S_IFREG | |
dfd2257a UD |
113 | # ifdef __S_IFIFO |
114 | # define S_IFIFO __S_IFIFO | |
115 | # endif | |
0ed99ce4 UD |
116 | # ifdef __S_IFLNK |
117 | # define S_IFLNK __S_IFLNK | |
118 | # endif | |
1e4380f8 UD |
119 | # if (defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN2K) \ |
120 | && defined __S_IFSOCK | |
0ed99ce4 | 121 | # define S_IFSOCK __S_IFSOCK |
9756dfe1 | 122 | # endif |
28f540f4 RM |
123 | #endif |
124 | ||
125 | /* Test macros for file types. */ | |
126 | ||
127 | #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask)) | |
128 | ||
dfd2257a UD |
129 | #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR) |
130 | #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR) | |
131 | #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK) | |
132 | #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG) | |
28f540f4 | 133 | #ifdef __S_IFIFO |
dfd2257a | 134 | # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO) |
28f540f4 | 135 | #endif |
0ed99ce4 UD |
136 | #ifdef __S_IFLNK |
137 | # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK) | |
138 | #endif | |
28f540f4 | 139 | |
6e86a7c2 | 140 | #ifdef __USE_BSD |
0ed99ce4 | 141 | # ifndef __S_IFLNK |
d71b808a | 142 | # define S_ISLNK(mode) 0 |
dfd2257a UD |
143 | # endif |
144 | # ifdef __S_IFSOCK | |
145 | # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK) | |
146 | # endif | |
28f540f4 RM |
147 | #endif |
148 | ||
f406c6f2 UD |
149 | /* These are from POSIX.1b. If the objects are not implemented using separate |
150 | distinct file types, the macros always will evaluate to zero. Unlike the | |
151 | other S_* macros the following three take a pointer to a `struct stat' | |
152 | object as the argument. */ | |
153 | #ifdef __USE_POSIX199309 | |
154 | # define S_TYPEISMQ(buf) __S_TYPEISMQ(buf) | |
155 | # define S_TYPEISSEM(buf) __S_TYPEISSEM(buf) | |
156 | # define S_TYPEISSHM(buf) __S_TYPEISSHM(buf) | |
157 | #endif | |
158 | ||
28f540f4 RM |
159 | |
160 | /* Protection bits. */ | |
161 | ||
162 | #define S_ISUID __S_ISUID /* Set user ID on execution. */ | |
163 | #define S_ISGID __S_ISGID /* Set group ID on execution. */ | |
164 | ||
0ed99ce4 | 165 | #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN |
28f540f4 | 166 | /* Save swapped text after use (sticky bit). This is pretty well obsolete. */ |
dfd2257a | 167 | # define S_ISVTX __S_ISVTX |
28f540f4 RM |
168 | #endif |
169 | ||
170 | #define S_IRUSR __S_IREAD /* Read by owner. */ | |
171 | #define S_IWUSR __S_IWRITE /* Write by owner. */ | |
172 | #define S_IXUSR __S_IEXEC /* Execute by owner. */ | |
173 | /* Read, write, and execute by owner. */ | |
174 | #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC) | |
175 | ||
dfd2257a | 176 | #if defined __USE_MISC && defined __USE_BSD |
ac72fbb1 | 177 | # define S_IREAD S_IRUSR |
dfd2257a | 178 | # define S_IWRITE S_IWUSR |
ac72fbb1 | 179 | # define S_IEXEC S_IXUSR |
28f540f4 RM |
180 | #endif |
181 | ||
182 | #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */ | |
183 | #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */ | |
184 | #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */ | |
185 | /* Read, write, and execute by group. */ | |
186 | #define S_IRWXG (S_IRWXU >> 3) | |
187 | ||
188 | #define S_IROTH (S_IRGRP >> 3) /* Read by others. */ | |
189 | #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */ | |
190 | #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */ | |
191 | /* Read, write, and execute by others. */ | |
192 | #define S_IRWXO (S_IRWXG >> 3) | |
193 | ||
194 | ||
fc4026d8 RM |
195 | #ifdef __USE_BSD |
196 | /* Macros for common mode bit masks. */ | |
dfd2257a | 197 | # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */ |
ac72fbb1 | 198 | # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */ |
dfd2257a | 199 | # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/ |
fc4026d8 | 200 | |
dfd2257a | 201 | # define S_BLKSIZE 512 /* Block size for `st_blocks'. */ |
fc4026d8 RM |
202 | #endif |
203 | ||
204 | ||
bdbf022d | 205 | #ifndef __USE_FILE_OFFSET64 |
28f540f4 | 206 | /* Get file attributes for FILE and put them in BUF. */ |
98cbe360 UD |
207 | extern int stat (__const char *__restrict __file, |
208 | struct stat *__restrict __buf) __THROW; | |
bdbf022d | 209 | |
28f540f4 RM |
210 | /* Get file attributes for the file, device, pipe, or socket |
211 | that file descriptor FD is open on and put them in BUF. */ | |
c1422e5b | 212 | extern int fstat (int __fd, struct stat *__buf) __THROW; |
dfd2257a | 213 | #else |
01cad722 | 214 | # ifdef __REDIRECT |
c1422e5b | 215 | extern int __REDIRECT (stat, |
98cbe360 UD |
216 | (__const char *__restrict __file, |
217 | struct stat *__restrict __buf) __THROW, | |
01cad722 | 218 | stat64); |
c1422e5b | 219 | extern int __REDIRECT (fstat, (int __fd, struct stat *__buf) __THROW, fstat64); |
01cad722 UD |
220 | # else |
221 | # define stat stat64 | |
222 | # define fstat fstat64 | |
223 | # endif | |
dfd2257a UD |
224 | #endif |
225 | #ifdef __USE_LARGEFILE64 | |
98cbe360 UD |
226 | extern int stat64 (__const char *__restrict __file, |
227 | struct stat64 *__restrict __buf) __THROW; | |
c1422e5b | 228 | extern int fstat64 (int __fd, struct stat64 *__buf) __THROW; |
dfd2257a | 229 | #endif |
28f540f4 | 230 | |
dfd2257a UD |
231 | #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED |
232 | # ifndef __USE_FILE_OFFSET64 | |
bdbf022d UD |
233 | /* Get file attributes about FILE and put them in BUF. |
234 | If FILE is a symbolic link, do not follow it. */ | |
98cbe360 UD |
235 | extern int lstat (__const char *__restrict __file, |
236 | struct stat *__restrict __buf) __THROW; | |
dfd2257a | 237 | # else |
01cad722 | 238 | # ifdef __REDIRECT |
c1422e5b | 239 | extern int __REDIRECT (lstat, |
98cbe360 UD |
240 | (__const char *__restrict __file, |
241 | struct stat *__restrict __buf) __THROW, | |
01cad722 UD |
242 | lstat64); |
243 | # else | |
244 | # define lstat lstat64 | |
245 | # endif | |
dfd2257a UD |
246 | # endif |
247 | # ifdef __USE_LARGEFILE64 | |
98cbe360 UD |
248 | extern int lstat64 (__const char *__restrict __file, |
249 | struct stat64 *__restrict __buf) __THROW; | |
dfd2257a | 250 | # endif |
28f540f4 RM |
251 | #endif |
252 | ||
253 | /* Set file access permissions for FILE to MODE. | |
f4b07664 | 254 | If FILE is a symbolic link, this affects its target instead. */ |
c1422e5b | 255 | extern int chmod (__const char *__file, __mode_t __mode) __THROW; |
28f540f4 | 256 | |
f4b07664 RM |
257 | #ifdef __USE_BSD |
258 | /* Set file access permissions for FILE to MODE. | |
259 | If FILE is a symbolic link, this affects the link itself | |
260 | rather than its target. */ | |
261 | extern int lchmod (__const char *__file, __mode_t __mode) __THROW; | |
262 | #endif | |
263 | ||
28f540f4 | 264 | /* Set file access permissions of the file FD is open on to MODE. */ |
dfd2257a | 265 | #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED |
c1422e5b | 266 | extern int fchmod (int __fd, __mode_t __mode) __THROW; |
28f540f4 RM |
267 | #endif |
268 | ||
269 | ||
270 | /* Set the file creation mask of the current process to MASK, | |
271 | and return the old creation mask. */ | |
c1422e5b | 272 | extern __mode_t umask (__mode_t __mask) __THROW; |
28f540f4 RM |
273 | |
274 | #ifdef __USE_GNU | |
275 | /* Get the current `umask' value without changing it. | |
276 | This function is only available under the GNU Hurd. */ | |
c1422e5b | 277 | extern __mode_t getumask (void) __THROW; |
28f540f4 RM |
278 | #endif |
279 | ||
280 | /* Create a new directory named PATH, with permission bits MODE. */ | |
c1422e5b | 281 | extern int mkdir (__const char *__path, __mode_t __mode) __THROW; |
28f540f4 RM |
282 | |
283 | /* Create a device file named PATH, with permission and special bits MODE | |
284 | and device number DEV (which can be constructed from major and minor | |
285 | device numbers with the `makedev' macro above). */ | |
dfd2257a | 286 | #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED |
c1422e5b UD |
287 | extern int mknod (__const char *__path, __mode_t __mode, __dev_t __dev) |
288 | __THROW; | |
28f540f4 RM |
289 | #endif |
290 | ||
291 | ||
292 | /* Create a new FIFO named PATH, with permission bits MODE. */ | |
c1422e5b | 293 | extern int mkfifo (__const char *__path, __mode_t __mode) __THROW; |
c59928df | 294 | \f |
5107cf1d UD |
295 | /* To allow the `struct stat' structure and the file type `mode_t' |
296 | bits to vary without changing shared library major version number, | |
297 | the `stat' family of functions and `mknod' are in fact inline | |
298 | wrappers around calls to `xstat', `fxstat', `lxstat', and `xmknod', | |
299 | which all take a leading version-number argument designating the | |
300 | data structure and bits used. <bits/stat.h> defines _STAT_VER with | |
301 | the version number corresponding to `struct stat' as defined in | |
302 | that file; and _MKNOD_VER with the version number corresponding to | |
303 | the S_IF* macros defined therein. It is arranged that when not | |
304 | inlined these function are always statically linked; that way a | |
305 | dynamically-linked executable always encodes the version number | |
306 | corresponding to the data structures it uses, so the `x' functions | |
307 | in the shared library can adapt without needing to recompile all | |
308 | callers. */ | |
c59928df RM |
309 | |
310 | #ifndef _STAT_VER | |
dfd2257a | 311 | # define _STAT_VER 0 |
c59928df RM |
312 | #endif |
313 | #ifndef _MKNOD_VER | |
dfd2257a | 314 | # define _MKNOD_VER 0 |
c59928df RM |
315 | #endif |
316 | ||
317 | /* Wrappers for stat and mknod system calls. */ | |
9756dfe1 | 318 | #ifndef __USE_FILE_OFFSET64 |
c1422e5b UD |
319 | extern int __fxstat (int __ver, int __fildes, struct stat *__stat_buf) __THROW; |
320 | extern int __xstat (int __ver, __const char *__filename, | |
321 | struct stat *__stat_buf) __THROW; | |
322 | extern int __lxstat (int __ver, __const char *__filename, | |
323 | struct stat *__stat_buf) __THROW; | |
9756dfe1 | 324 | #else |
01cad722 | 325 | # ifdef __REDIRECT |
c1422e5b UD |
326 | extern int __REDIRECT (__fxstat, (int __ver, int __fildes, |
327 | struct stat *__stat_buf) __THROW, | |
328 | __fxstat64); | |
329 | extern int __REDIRECT (__xstat, (int __ver, __const char *__filename, | |
330 | struct stat *__stat_buf) __THROW, __xstat64); | |
331 | extern int __REDIRECT (__lxstat, (int __ver, __const char *__filename, | |
332 | struct stat *__stat_buf) __THROW, | |
333 | __lxstat64); | |
01cad722 UD |
334 | |
335 | # else | |
336 | # define __fxstat __fxstat64 | |
337 | # define __xstat __xstat64 | |
338 | # define __lxstat __lxstat64 | |
339 | # endif | |
9756dfe1 | 340 | #endif |
01cad722 | 341 | |
9756dfe1 | 342 | #ifdef __USE_LARGEFILE64 |
c1422e5b UD |
343 | extern int __fxstat64 (int __ver, int __fildes, struct stat64 *__stat_buf) |
344 | __THROW; | |
345 | extern int __xstat64 (int __ver, __const char *__filename, | |
346 | struct stat64 *__stat_buf) __THROW; | |
347 | extern int __lxstat64 (int __ver, __const char *__filename, | |
348 | struct stat64 *__stat_buf) __THROW; | |
dfd2257a | 349 | #endif |
c1422e5b UD |
350 | extern int __xmknod (int __ver, __const char *__path, __mode_t __mode, |
351 | __dev_t *__dev) __THROW; | |
c59928df | 352 | |
dfd2257a | 353 | #if defined __GNUC__ && __GNUC__ >= 2 |
99e46354 | 354 | /* Inlined versions of the real stat and mknod functions. */ |
c59928df | 355 | |
99e46354 UD |
356 | extern __inline__ int stat (__const char *__path, |
357 | struct stat *__statbuf) __THROW | |
dfd2257a | 358 | { |
dfd2257a | 359 | return __xstat (_STAT_VER, __path, __statbuf); |
dfd2257a UD |
360 | } |
361 | ||
dfd2257a | 362 | # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED |
99e46354 UD |
363 | extern __inline__ int lstat (__const char *__path, |
364 | struct stat *__statbuf) __THROW | |
dfd2257a | 365 | { |
dfd2257a | 366 | return __lxstat (_STAT_VER, __path, __statbuf); |
dfd2257a UD |
367 | } |
368 | # endif | |
c59928df | 369 | |
99e46354 | 370 | extern __inline__ int fstat (int __fd, struct stat *__statbuf) __THROW |
dfd2257a | 371 | { |
dfd2257a | 372 | return __fxstat (_STAT_VER, __fd, __statbuf); |
dfd2257a | 373 | } |
c59928df | 374 | |
dfd2257a | 375 | # if defined __USE_MISC || defined __USE_BSD |
99e46354 UD |
376 | extern __inline__ int mknod (__const char *__path, __mode_t __mode, |
377 | __dev_t __dev) __THROW | |
bdbf022d UD |
378 | { |
379 | return __xmknod (_MKNOD_VER, __path, __mode, &__dev); | |
380 | } | |
dfd2257a UD |
381 | # endif |
382 | ||
5e087c71 UD |
383 | # if defined __USE_LARGEFILE64 \ |
384 | && (! defined __USE_FILE_OFFSET64 \ | |
385 | || (defined __REDIRECT && defined __OPTIMIZE__)) | |
99e46354 UD |
386 | extern __inline__ int stat64 (__const char *__path, |
387 | struct stat64 *__statbuf) __THROW | |
dfd2257a UD |
388 | { |
389 | return __xstat64 (_STAT_VER, __path, __statbuf); | |
390 | } | |
391 | ||
392 | # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED | |
99e46354 UD |
393 | extern __inline__ int lstat64 (__const char *__path, |
394 | struct stat64 *__statbuf) __THROW | |
dfd2257a UD |
395 | { |
396 | return __lxstat64 (_STAT_VER, __path, __statbuf); | |
397 | } | |
398 | # endif | |
399 | ||
99e46354 | 400 | extern __inline__ int fstat64 (int __fd, struct stat64 *__statbuf) __THROW |
dfd2257a UD |
401 | { |
402 | return __fxstat64 (_STAT_VER, __fd, __statbuf); | |
403 | } | |
404 | # endif | |
c59928df RM |
405 | |
406 | #endif | |
28f540f4 RM |
407 | |
408 | __END_DECLS | |
409 | ||
c59928df | 410 | |
28f540f4 | 411 | #endif /* sys/stat.h */ |