]> git.ipfire.org Git - thirdparty/glibc.git/blob - io/sys/stat.h
Update.
[thirdparty/glibc.git] / io / sys / stat.h
1 /* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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. */
18
19 /*
20 * POSIX Standard: 5.6 File Characteristics <sys/stat.h>
21 */
22
23 #ifndef _SYS_STAT_H
24 #define _SYS_STAT_H 1
25
26 #include <features.h>
27
28 #include <bits/types.h> /* For __mode_t and __dev_t. */
29
30 #ifdef __USE_UNIX98
31 /* The Single Unix specification says that some more types are
32 available here. */
33 # ifndef dev_t
34 typedef __dev_t dev_t;
35 # define dev_t dev_t
36 # endif
37
38 # ifndef gid_t
39 typedef __gid_t gid_t;
40 # define gid_t gid_t
41 # endif
42
43 # ifndef ino_t
44 # ifndef __USE_FILE_OFFSET64
45 typedef __ino_t ino_t;
46 # else
47 typedef __ino64_t ino_t;
48 # endif
49 # define ino_t ino_t
50 # endif
51
52 # ifndef mode_t
53 typedef __mode_t mode_t;
54 # define mode_t mode_t
55 # endif
56
57 # ifndef nlink_t
58 typedef __nlink_t nlink_t;
59 # define nlink_t nlink_t
60 # endif
61
62 # ifndef off_t
63 # ifndef __USE_FILE_OFFSET64
64 typedef __off_t off_t;
65 # else
66 typedef __off64_t off_t;
67 # endif
68 # define off_t off_t
69 # endif
70
71 # ifndef uid_t
72 typedef __uid_t uid_t;
73 # define uid_t uid_t
74 # endif
75
76 # ifndef pid_t
77 typedef __pid_t pid_t;
78 # define pid_t pid_t
79 # endif
80 #endif /* Unix98 */
81
82 __BEGIN_DECLS
83
84 #include <bits/stat.h>
85
86 #if defined __USE_BSD || defined __USE_MISC || defined __USE_UNIX98
87 # define S_IFMT __S_IFMT
88 # define S_IFDIR __S_IFDIR
89 # define S_IFCHR __S_IFCHR
90 # define S_IFBLK __S_IFBLK
91 # define S_IFREG __S_IFREG
92 # ifdef __S_IFIFO
93 # define S_IFIFO __S_IFIFO
94 # endif
95 # ifndef __USE_UNIX98
96 # ifdef __S_IFLNK
97 # define S_IFLNK __S_IFLNK
98 # endif
99 # ifdef __S_IFSOCK
100 # define S_IFSOCK __S_IFSOCK
101 # endif
102 # endif
103 #endif
104
105 /* Test macros for file types. */
106
107 #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
108
109 #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
110 #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR)
111 #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK)
112 #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
113 #ifdef __S_IFIFO
114 # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
115 #endif
116
117 #ifdef __USE_BSD
118 # ifdef __S_IFLNK
119 # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
120 # else
121 # define S_ISLNK(mode) 0
122 # endif
123 # ifdef __S_IFSOCK
124 # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
125 # endif
126 #endif
127
128
129 /* Protection bits. */
130
131 #define S_ISUID __S_ISUID /* Set user ID on execution. */
132 #define S_ISGID __S_ISGID /* Set group ID on execution. */
133
134 #if defined __USE_BSD || defined __USE_MISC
135 /* Save swapped text after use (sticky bit). This is pretty well obsolete. */
136 # define S_ISVTX __S_ISVTX
137 #endif
138
139 #define S_IRUSR __S_IREAD /* Read by owner. */
140 #define S_IWUSR __S_IWRITE /* Write by owner. */
141 #define S_IXUSR __S_IEXEC /* Execute by owner. */
142 /* Read, write, and execute by owner. */
143 #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
144
145 #if defined __USE_MISC && defined __USE_BSD
146 # define S_IREAD S_IRUSR
147 # define S_IWRITE S_IWUSR
148 # define S_IEXEC S_IXUSR
149 #endif
150
151 #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
152 #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
153 #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
154 /* Read, write, and execute by group. */
155 #define S_IRWXG (S_IRWXU >> 3)
156
157 #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
158 #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
159 #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
160 /* Read, write, and execute by others. */
161 #define S_IRWXO (S_IRWXG >> 3)
162
163
164 #ifdef __USE_BSD
165 /* Macros for common mode bit masks. */
166 # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
167 # define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
168 # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
169
170 # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
171 #endif
172
173
174 /* Get file attributes for FILE and put them in BUF. */
175 extern int __stat __P ((__const char *__file, struct stat *__buf));
176 #ifndef __USE_FILE_OFFSET64
177 extern int stat __P ((__const char *__file, struct stat *__buf));
178 #else
179 extern int stat __P ((__const char *__file, struct stat *__buf))
180 __asm__ ("stat64");
181 #endif
182 #ifdef __USE_LARGEFILE64
183 extern int stat64 __P ((__const char *__file, struct stat64 *__buf));
184 #endif
185
186 /* Get file attributes for the file, device, pipe, or socket
187 that file descriptor FD is open on and put them in BUF. */
188 extern int __fstat __P ((int __fd, struct stat *__buf));
189 #ifndef __USE_FILE_OFFSET64
190 extern int fstat __P ((int __fd, struct stat *__buf));
191 #else
192 extern int fstat __P ((int __fd, struct stat *__buf)) __asm__ ("fstat64");
193 #endif
194 #ifdef __USE_LARGEFILE64
195 extern int fstat64 __P ((int __fd, struct stat64 *__buf));
196 #endif
197
198 /* Get file attributes about FILE and put them in BUF.
199 If FILE is a symbolic link, do not follow it. */
200 extern int __lstat __P ((__const char *__file, struct stat *__buf));
201 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
202 # ifndef __USE_FILE_OFFSET64
203 extern int lstat __P ((__const char *__file, struct stat *__buf));
204 # else
205 extern int lstat __P ((__const char *__file, struct stat *__buf))
206 __asm__ ("lstat64");
207 # endif
208 # ifdef __USE_LARGEFILE64
209 extern int lstat64 __P ((__const char *__file, struct stat64 *__buf));
210 # endif
211 #endif
212
213 /* Set file access permissions for FILE to MODE.
214 This takes an `int' MODE argument because that
215 is what `mode_t's get widened to. */
216 extern int __chmod __P ((__const char *__file, __mode_t __mode));
217 extern int chmod __P ((__const char *__file, __mode_t __mode));
218
219 /* Set file access permissions of the file FD is open on to MODE. */
220 extern int __fchmod __P ((int __fd, __mode_t __mode));
221 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
222 extern int fchmod __P ((int __fd, __mode_t __mode));
223 #endif
224
225
226 /* Set the file creation mask of the current process to MASK,
227 and return the old creation mask. */
228 extern __mode_t __umask __P ((__mode_t __mask));
229 extern __mode_t umask __P ((__mode_t __mask));
230
231 #ifdef __USE_GNU
232 /* Get the current `umask' value without changing it.
233 This function is only available under the GNU Hurd. */
234 extern __mode_t getumask __P ((void));
235 #endif
236
237 /* Create a new directory named PATH, with permission bits MODE. */
238 extern int __mkdir __P ((__const char *__path, __mode_t __mode));
239 extern int mkdir __P ((__const char *__path, __mode_t __mode));
240
241 /* Create a device file named PATH, with permission and special bits MODE
242 and device number DEV (which can be constructed from major and minor
243 device numbers with the `makedev' macro above). */
244 extern int __mknod __P ((__const char *__path,
245 __mode_t __mode, __dev_t __dev));
246 #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
247 extern int mknod __P ((__const char *__path,
248 __mode_t __mode, __dev_t __dev));
249 #endif
250
251
252 /* Create a new FIFO named PATH, with permission bits MODE. */
253 extern int mkfifo __P ((__const char *__path, __mode_t __mode));
254 \f
255 /* To allow the `struct stat' structure and the file type `mode_t'
256 bits to vary without changing shared library major version number,
257 the `stat' family of functions and `mknod' are in fact inline
258 wrappers around calls to `xstat', `fxstat', `lxstat', and `xmknod',
259 which all take a leading version-number argument designating the
260 data structure and bits used. <bits/stat.h> defines _STAT_VER with
261 the version number corresponding to `struct stat' as defined in
262 that file; and _MKNOD_VER with the version number corresponding to
263 the S_IF* macros defined therein. It is arranged that when not
264 inlined these function are always statically linked; that way a
265 dynamically-linked executable always encodes the version number
266 corresponding to the data structures it uses, so the `x' functions
267 in the shared library can adapt without needing to recompile all
268 callers. */
269
270 #ifndef _STAT_VER
271 # define _STAT_VER 0
272 #endif
273 #ifndef _MKNOD_VER
274 # define _MKNOD_VER 0
275 #endif
276
277 /* Wrappers for stat and mknod system calls. */
278 #ifndef __USE_FILE_OFFSET64
279 extern int __fxstat __P ((int __ver, int __fildes,
280 struct stat *__stat_buf));
281 extern int __xstat __P ((int __ver, __const char *__filename,
282 struct stat *__stat_buf));
283 extern int __lxstat __P ((int __ver, __const char *__filename,
284 struct stat *__stat_buf));
285 #else
286 extern int __fxstat __P ((int __ver, int __fildes,
287 struct stat *__stat_buf))
288 __asm__ ("__fxstat64");
289 extern int __xstat __P ((int __ver, __const char *__filename,
290 struct stat *__stat_buf))
291 __asm__ ("__xstat64");
292 extern int __lxstat __P ((int __ver, __const char *__filename,
293 struct stat *__stat_buf))
294 __asm__ ("__lxstat64");
295 #endif
296 #ifdef __USE_LARGEFILE64
297 extern int __fxstat64 __P ((int __ver, int __fildes,
298 struct stat64 *__stat_buf));
299 extern int __xstat64 __P ((int __ver, __const char *__filename,
300 struct stat64 *__stat_buf));
301 extern int __lxstat64 __P ((int __ver, __const char *__filename,
302 struct stat64 *__stat_buf));
303 #endif
304 extern int __xmknod __P ((int __ver, __const char *__path,
305 __mode_t __mode, __dev_t *__dev));
306
307 #if defined __GNUC__ && __GNUC__ >= 2
308 /* Inlined versions of the real stat and mknod functions. */
309
310 extern __inline__ int __stat (__const char *__path, struct stat *__statbuf)
311 {
312 return __xstat (_STAT_VER, __path, __statbuf);
313 }
314 extern __inline__ int stat (__const char *__path, struct stat *__statbuf)
315 {
316 return __xstat (_STAT_VER, __path, __statbuf);
317 }
318
319 extern __inline__ int __lstat (__const char *__path, struct stat *__statbuf)
320 {
321 return __lxstat (_STAT_VER, __path, __statbuf);
322 }
323 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
324 extern __inline__ int lstat (__const char *__path, struct stat *__statbuf)
325 {
326 return __lxstat (_STAT_VER, __path, __statbuf);
327 }
328 # endif
329
330 extern __inline__ int __fstat (int __fd, struct stat *__statbuf)
331 {
332 return __fxstat (_STAT_VER, __fd, __statbuf);
333 }
334 extern __inline__ int fstat (int __fd, struct stat *__statbuf)
335 {
336 return __fxstat (_STAT_VER, __fd, __statbuf);
337 }
338
339 extern __inline__ int __mknod (__const char *__path, __mode_t __mode,
340 __dev_t __dev)
341 { return __xmknod (_MKNOD_VER, __path, __mode, &__dev); }
342 # if defined __USE_MISC || defined __USE_BSD
343 extern __inline__ int mknod (__const char *__path, __mode_t __mode,
344 __dev_t __dev)
345 { return __xmknod (_MKNOD_VER, __path, __mode, &__dev); }
346 # endif
347
348 # ifdef __USE_LARGEFILE64
349 extern __inline__ int stat64 (__const char *__path, struct stat64 *__statbuf)
350 {
351 return __xstat64 (_STAT_VER, __path, __statbuf);
352 }
353
354 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
355 extern __inline__ int lstat64 (__const char *__path, struct stat64 *__statbuf)
356 {
357 return __lxstat64 (_STAT_VER, __path, __statbuf);
358 }
359 # endif
360
361 extern __inline__ int fstat64 (int __fd, struct stat64 *__statbuf)
362 {
363 return __fxstat64 (_STAT_VER, __fd, __statbuf);
364 }
365 # endif
366
367 #endif
368
369 __END_DECLS
370
371
372 #endif /* sys/stat.h */