Update.
[glibc.git] / io / sys / stat.h
blob1a674b1df224becc8503f7297c7e0d0a49f18ad4
1 /* Copyright (C) 1991, 92, 1995-1999, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
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
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 * POSIX Standard: 5.6 File Characteristics <sys/stat.h>
23 #ifndef _SYS_STAT_H
24 #define _SYS_STAT_H 1
26 #include <features.h>
28 #include <bits/types.h> /* For __mode_t and __dev_t. */
30 #ifdef __USE_XOPEN
31 # define __need_time_t
32 # include <time.h> /* For time_t. */
34 /* The Single Unix specification says that some more types are
35 available here. */
36 # ifndef __dev_t_defined
37 typedef __dev_t dev_t;
38 # define __dev_t_defined
39 # endif
41 # ifndef __gid_t_defined
42 typedef __gid_t gid_t;
43 # define __gid_t_defined
44 # endif
46 # ifndef __ino_t_defined
47 # ifndef __USE_FILE_OFFSET64
48 typedef __ino_t ino_t;
49 # else
50 typedef __ino64_t ino_t;
51 # endif
52 # define __ino_t_defined
53 # endif
55 # ifndef __mode_t_defined
56 typedef __mode_t mode_t;
57 # define __mode_t_defined
58 # endif
60 # ifndef __nlink_t_defined
61 typedef __nlink_t nlink_t;
62 # define __nlink_t_defined
63 # endif
65 # ifndef __off_t_defined
66 # ifndef __USE_FILE_OFFSET64
67 typedef __off_t off_t;
68 # else
69 typedef __off64_t off_t;
70 # endif
71 # define __off_t_defined
72 # endif
74 # ifndef __uid_t_defined
75 typedef __uid_t uid_t;
76 # define __uid_t_defined
77 # endif
78 #endif /* X/Open */
80 #ifdef __USE_UNIX98
81 # ifndef __blkcnt_t_defined
82 # ifndef __USE_FILE_OFFSET64
83 typedef __blkcnt_t blkcnt_t;
84 # else
85 typedef __blkcnt64_t blkcnt_t;
86 # endif
87 # define __blkcnt_t_defined
88 # endif
90 # ifndef __blksize_t_defined
91 typedef __blksize_t blksize_t;
92 # define __blksize_t_defined
93 # endif
94 #endif /* Unix98 */
96 __BEGIN_DECLS
98 #include <bits/stat.h>
100 #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
101 # define S_IFMT __S_IFMT
102 # define S_IFDIR __S_IFDIR
103 # define S_IFCHR __S_IFCHR
104 # define S_IFBLK __S_IFBLK
105 # define S_IFREG __S_IFREG
106 # ifdef __S_IFIFO
107 # define S_IFIFO __S_IFIFO
108 # endif
109 # ifdef __S_IFLNK
110 # define S_IFLNK __S_IFLNK
111 # endif
112 # if (defined __USE_BSD || defined __USE_MISC) && defined __S_IFSOCK
113 # define S_IFSOCK __S_IFSOCK
114 # endif
115 #endif
117 /* Test macros for file types. */
119 #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
121 #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
122 #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR)
123 #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK)
124 #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
125 #ifdef __S_IFIFO
126 # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
127 #endif
128 #ifdef __S_IFLNK
129 # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
130 #endif
132 #ifdef __USE_BSD
133 # ifndef __S_IFLNK
134 # define S_ISLNK(mode) 0
135 # endif
136 # ifdef __S_IFSOCK
137 # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
138 # endif
139 #endif
142 /* Protection bits. */
144 #define S_ISUID __S_ISUID /* Set user ID on execution. */
145 #define S_ISGID __S_ISGID /* Set group ID on execution. */
147 #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
148 /* Save swapped text after use (sticky bit). This is pretty well obsolete. */
149 # define S_ISVTX __S_ISVTX
150 #endif
152 #define S_IRUSR __S_IREAD /* Read by owner. */
153 #define S_IWUSR __S_IWRITE /* Write by owner. */
154 #define S_IXUSR __S_IEXEC /* Execute by owner. */
155 /* Read, write, and execute by owner. */
156 #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
158 #if defined __USE_MISC && defined __USE_BSD
159 # define S_IREAD S_IRUSR
160 # define S_IWRITE S_IWUSR
161 # define S_IEXEC S_IXUSR
162 #endif
164 #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
165 #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
166 #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
167 /* Read, write, and execute by group. */
168 #define S_IRWXG (S_IRWXU >> 3)
170 #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
171 #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
172 #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
173 /* Read, write, and execute by others. */
174 #define S_IRWXO (S_IRWXG >> 3)
177 #ifdef __USE_BSD
178 /* Macros for common mode bit masks. */
179 # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
180 # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
181 # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
183 # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
184 #endif
187 #ifndef __USE_FILE_OFFSET64
188 /* Get file attributes for FILE and put them in BUF. */
189 extern int stat (__const char *__file, struct stat *__buf) __THROW;
191 /* Get file attributes for the file, device, pipe, or socket
192 that file descriptor FD is open on and put them in BUF. */
193 extern int fstat (int __fd, struct stat *__buf) __THROW;
194 #else
195 # ifdef __REDIRECT
196 extern int __REDIRECT (stat,
197 (__const char *__file, struct stat *__buf) __THROW,
198 stat64);
199 extern int __REDIRECT (fstat, (int __fd, struct stat *__buf) __THROW, fstat64);
200 # else
201 # define stat stat64
202 # define fstat fstat64
203 # endif
204 #endif
205 #ifdef __USE_LARGEFILE64
206 extern int stat64 (__const char *__file, struct stat64 *__buf) __THROW;
207 extern int fstat64 (int __fd, struct stat64 *__buf) __THROW;
208 #endif
210 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
211 # ifndef __USE_FILE_OFFSET64
212 /* Get file attributes about FILE and put them in BUF.
213 If FILE is a symbolic link, do not follow it. */
214 extern int lstat (__const char *__file, struct stat *__buf) __THROW;
215 # else
216 # ifdef __REDIRECT
217 extern int __REDIRECT (lstat,
218 (__const char *__file, struct stat *__buf) __THROW,
219 lstat64);
220 # else
221 # define lstat lstat64
222 # endif
223 # endif
224 # ifdef __USE_LARGEFILE64
225 extern int lstat64 (__const char *__file, struct stat64 *__buf) __THROW;
226 # endif
227 #endif
229 /* Set file access permissions for FILE to MODE.
230 This takes an `int' MODE argument because that
231 is what `mode_t's get widened to. */
232 extern int chmod (__const char *__file, __mode_t __mode) __THROW;
234 /* Set file access permissions of the file FD is open on to MODE. */
235 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
236 extern int fchmod (int __fd, __mode_t __mode) __THROW;
237 #endif
240 /* Set the file creation mask of the current process to MASK,
241 and return the old creation mask. */
242 extern __mode_t umask (__mode_t __mask) __THROW;
244 #ifdef __USE_GNU
245 /* Get the current `umask' value without changing it.
246 This function is only available under the GNU Hurd. */
247 extern __mode_t getumask (void) __THROW;
248 #endif
250 /* Create a new directory named PATH, with permission bits MODE. */
251 extern int mkdir (__const char *__path, __mode_t __mode) __THROW;
253 /* Create a device file named PATH, with permission and special bits MODE
254 and device number DEV (which can be constructed from major and minor
255 device numbers with the `makedev' macro above). */
256 #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
257 extern int mknod (__const char *__path, __mode_t __mode, __dev_t __dev)
258 __THROW;
259 #endif
262 /* Create a new FIFO named PATH, with permission bits MODE. */
263 extern int mkfifo (__const char *__path, __mode_t __mode) __THROW;
265 /* To allow the `struct stat' structure and the file type `mode_t'
266 bits to vary without changing shared library major version number,
267 the `stat' family of functions and `mknod' are in fact inline
268 wrappers around calls to `xstat', `fxstat', `lxstat', and `xmknod',
269 which all take a leading version-number argument designating the
270 data structure and bits used. <bits/stat.h> defines _STAT_VER with
271 the version number corresponding to `struct stat' as defined in
272 that file; and _MKNOD_VER with the version number corresponding to
273 the S_IF* macros defined therein. It is arranged that when not
274 inlined these function are always statically linked; that way a
275 dynamically-linked executable always encodes the version number
276 corresponding to the data structures it uses, so the `x' functions
277 in the shared library can adapt without needing to recompile all
278 callers. */
280 #ifndef _STAT_VER
281 # define _STAT_VER 0
282 #endif
283 #ifndef _MKNOD_VER
284 # define _MKNOD_VER 0
285 #endif
287 /* Wrappers for stat and mknod system calls. */
288 #ifndef __USE_FILE_OFFSET64
289 extern int __fxstat (int __ver, int __fildes, struct stat *__stat_buf) __THROW;
290 extern int __xstat (int __ver, __const char *__filename,
291 struct stat *__stat_buf) __THROW;
292 extern int __lxstat (int __ver, __const char *__filename,
293 struct stat *__stat_buf) __THROW;
294 #else
295 # ifdef __REDIRECT
296 extern int __REDIRECT (__fxstat, (int __ver, int __fildes,
297 struct stat *__stat_buf) __THROW,
298 __fxstat64);
299 extern int __REDIRECT (__xstat, (int __ver, __const char *__filename,
300 struct stat *__stat_buf) __THROW, __xstat64);
301 extern int __REDIRECT (__lxstat, (int __ver, __const char *__filename,
302 struct stat *__stat_buf) __THROW,
303 __lxstat64);
305 # else
306 # define __fxstat __fxstat64
307 # define __xstat __xstat64
308 # define __lxstat __lxstat64
309 # endif
310 #endif
312 #ifdef __USE_LARGEFILE64
313 extern int __fxstat64 (int __ver, int __fildes, struct stat64 *__stat_buf)
314 __THROW;
315 extern int __xstat64 (int __ver, __const char *__filename,
316 struct stat64 *__stat_buf) __THROW;
317 extern int __lxstat64 (int __ver, __const char *__filename,
318 struct stat64 *__stat_buf) __THROW;
319 #endif
320 extern int __xmknod (int __ver, __const char *__path, __mode_t __mode,
321 __dev_t *__dev) __THROW;
323 #if defined __GNUC__ && __GNUC__ >= 2
324 /* Inlined versions of the real stat and mknod functions. */
326 extern __inline__ int stat (__const char *__path,
327 struct stat *__statbuf) __THROW
329 return __xstat (_STAT_VER, __path, __statbuf);
332 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
333 extern __inline__ int lstat (__const char *__path,
334 struct stat *__statbuf) __THROW
336 return __lxstat (_STAT_VER, __path, __statbuf);
338 # endif
340 extern __inline__ int fstat (int __fd, struct stat *__statbuf) __THROW
342 return __fxstat (_STAT_VER, __fd, __statbuf);
345 # if defined __USE_MISC || defined __USE_BSD
346 extern __inline__ int mknod (__const char *__path, __mode_t __mode,
347 __dev_t __dev) __THROW
349 return __xmknod (_MKNOD_VER, __path, __mode, &__dev);
351 # endif
353 # ifdef __USE_LARGEFILE64
354 extern __inline__ int stat64 (__const char *__path,
355 struct stat64 *__statbuf) __THROW
357 return __xstat64 (_STAT_VER, __path, __statbuf);
360 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
361 extern __inline__ int lstat64 (__const char *__path,
362 struct stat64 *__statbuf) __THROW
364 return __lxstat64 (_STAT_VER, __path, __statbuf);
366 # endif
368 extern __inline__ int fstat64 (int __fd, struct stat64 *__statbuf) __THROW
370 return __fxstat64 (_STAT_VER, __fd, __statbuf);
372 # endif
374 #endif
376 __END_DECLS
379 #endif /* sys/stat.h */