Update.
[glibc.git] / io / sys / stat.h
blob01bc00165ee97086c7bb6f776bc294df354bf526
1 /* Copyright (C) 1991, 1992, 1995, 1996, 1997 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 __BEGIN_DECLS
32 #include <bits/stat.h>
34 #if defined __USE_BSD || defined __USE_MISC
35 # define S_IFMT __S_IFMT
36 # define S_IFDIR __S_IFDIR
37 # define S_IFCHR __S_IFCHR
38 # define S_IFBLK __S_IFBLK
39 # define S_IFREG __S_IFREG
40 # ifdef __S_IFLNK
41 # define S_IFLNK __S_IFLNK
42 # endif
43 # ifdef __S_IFSOCK
44 # define S_IFSOCK __S_IFSOCK
45 # endif
46 # ifdef __S_IFIFO
47 # define S_IFIFO __S_IFIFO
48 # endif
49 #endif
51 /* Test macros for file types. */
53 #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
55 #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
56 #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR)
57 #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK)
58 #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
59 #ifdef __S_IFIFO
60 # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
61 #endif
63 #ifdef __USE_BSD
64 # ifdef __S_IFLNK
65 # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
66 # endif
67 # ifdef __S_IFSOCK
68 # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
69 # endif
70 #endif
73 /* Protection bits. */
75 #define S_ISUID __S_ISUID /* Set user ID on execution. */
76 #define S_ISGID __S_ISGID /* Set group ID on execution. */
78 #if defined __USE_BSD || defined __USE_MISC
79 /* Save swapped text after use (sticky bit). This is pretty well obsolete. */
80 # define S_ISVTX __S_ISVTX
81 #endif
83 #define S_IRUSR __S_IREAD /* Read by owner. */
84 #define S_IWUSR __S_IWRITE /* Write by owner. */
85 #define S_IXUSR __S_IEXEC /* Execute by owner. */
86 /* Read, write, and execute by owner. */
87 #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
89 #if defined __USE_MISC && defined __USE_BSD
90 # define S_IREAD S_IRUSR
91 # define S_IWRITE S_IWUSR
92 # define S_IEXEC S_IXUSR
93 #endif
95 #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
96 #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
97 #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
98 /* Read, write, and execute by group. */
99 #define S_IRWXG (S_IRWXU >> 3)
101 #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
102 #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
103 #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
104 /* Read, write, and execute by others. */
105 #define S_IRWXO (S_IRWXG >> 3)
108 #ifdef __USE_BSD
109 /* Macros for common mode bit masks. */
110 # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
111 # define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
112 # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
114 # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
115 #endif
118 /* Get file attributes for FILE and put them in BUF. */
119 extern int __stat __P ((__const char *__file, struct stat *__buf));
120 #ifndef __USE_FILE_OFFSET64
121 extern int stat __P ((__const char *__file, struct stat *__buf));
122 #else
123 extern int stat __P ((__const char *__file, struct stat *__buf))
124 __asm__ ("stat64");
125 #endif
126 #ifdef __USE_LARGEFILE64
127 extern int stat64 __P ((__const char *__file, struct stat64 *__buf));
128 #endif
130 /* Get file attributes for the file, device, pipe, or socket
131 that file descriptor FD is open on and put them in BUF. */
132 extern int __fstat __P ((int __fd, struct stat *__buf));
133 #ifndef __USE_FILE_OFFSET64
134 extern int fstat __P ((int __fd, struct stat *__buf));
135 #else
136 extern int fstat __P ((int __fd, struct stat *__buf)) __asm__ ("fstat64");
137 #endif
138 #ifdef __USE_LARGEFILE64
139 extern int fstat64 __P ((int __fd, struct stat64 *__buf));
140 #endif
142 /* Get file attributes about FILE and put them in BUF.
143 If FILE is a symbolic link, do not follow it. */
144 extern int __lstat __P ((__const char *__file, struct stat *__buf));
145 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
146 # ifndef __USE_FILE_OFFSET64
147 extern int lstat __P ((__const char *__file, struct stat *__buf));
148 # else
149 extern int lstat __P ((__const char *__file, struct stat *__buf))
150 __asm__ ("lstat64");
151 # endif
152 # ifdef __USE_LARGEFILE64
153 extern int lstat64 __P ((__const char *__file, struct stat64 *__buf));
154 # endif
155 #endif
157 /* Set file access permissions for FILE to MODE.
158 This takes an `int' MODE argument because that
159 is what `mode_t's get widened to. */
160 extern int __chmod __P ((__const char *__file, __mode_t __mode));
161 extern int chmod __P ((__const char *__file, __mode_t __mode));
163 /* Set file access permissions of the file FD is open on to MODE. */
164 extern int __fchmod __P ((int __fd, __mode_t __mode));
165 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
166 extern int fchmod __P ((int __fd, __mode_t __mode));
167 #endif
170 /* Set the file creation mask of the current process to MASK,
171 and return the old creation mask. */
172 extern __mode_t __umask __P ((__mode_t __mask));
173 extern __mode_t umask __P ((__mode_t __mask));
175 #ifdef __USE_GNU
176 /* Get the current `umask' value without changing it.
177 This function is only available under the GNU Hurd. */
178 extern __mode_t getumask __P ((void));
179 #endif
181 /* Create a new directory named PATH, with permission bits MODE. */
182 extern int __mkdir __P ((__const char *__path, __mode_t __mode));
183 extern int mkdir __P ((__const char *__path, __mode_t __mode));
185 /* Create a device file named PATH, with permission and special bits MODE
186 and device number DEV (which can be constructed from major and minor
187 device numbers with the `makedev' macro above). */
188 extern int __mknod __P ((__const char *__path,
189 __mode_t __mode, __dev_t __dev));
190 #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
191 extern int mknod __P ((__const char *__path,
192 __mode_t __mode, __dev_t __dev));
193 #endif
196 /* Create a new FIFO named PATH, with permission bits MODE. */
197 extern int mkfifo __P ((__const char *__path, __mode_t __mode));
199 /* To allow the `struct stat' structure and the file type `mode_t'
200 bits to vary without changing shared library major version number,
201 the `stat' family of functions and `mknod' are in fact inline
202 wrappers around calls to `xstat', `fxstat', `lxstat', and `xmknod',
203 which all take a leading version-number argument designating the
204 data structure and bits used. <bits/stat.h> defines _STAT_VER with
205 the version number corresponding to `struct stat' as defined in
206 that file; and _MKNOD_VER with the version number corresponding to
207 the S_IF* macros defined therein. It is arranged that when not
208 inlined these function are always statically linked; that way a
209 dynamically-linked executable always encodes the version number
210 corresponding to the data structures it uses, so the `x' functions
211 in the shared library can adapt without needing to recompile all
212 callers. */
214 #ifndef _STAT_VER
215 # define _STAT_VER 0
216 #endif
217 #ifndef _MKNOD_VER
218 # define _MKNOD_VER 0
219 #endif
221 /* Wrappers for stat and mknod system calls. */
222 extern int __fxstat __P ((int __ver, int __fildes,
223 struct stat *__stat_buf));
224 extern int __xstat __P ((int __ver, __const char *__filename,
225 struct stat *__stat_buf));
226 extern int __lxstat __P ((int __ver, __const char *__filename,
227 struct stat *__stat_buf));
228 extern int __xmknod __P ((int __ver, __const char *__path,
229 __mode_t __mode, __dev_t *__dev));
230 #if defined __USE_LARGEFILE64 || defined __USE_FILE_OFFSET64
231 extern int __fxstat64 __P ((int __ver, int __fildes,
232 struct stat64 *__stat_buf));
233 extern int __xstat64 __P ((int __ver, __const char *__filename,
234 struct stat64 *__stat_buf));
235 extern int __lxstat64 __P ((int __ver, __const char *__filename,
236 struct stat64 *__stat_buf));
237 #endif
239 #if defined __GNUC__ && __GNUC__ >= 2
240 /* Inlined versions of the real stat and mknod functions. */
242 extern __inline__ int __stat (__const char *__path, struct stat *__statbuf)
244 # ifndef __USE_FILE_OFFSET64
245 return __xstat (_STAT_VER, __path, __statbuf);
246 # else
247 return __xstat64 (_STAT_VER, __path, __statbuf);
248 # endif
250 extern __inline__ int stat (__const char *__path, struct stat *__statbuf)
252 # ifndef __USE_FILE_OFFSET64
253 return __xstat (_STAT_VER, __path, __statbuf);
254 # else
255 return __xstat64 (_STAT_VER, __path, __statbuf);
256 # endif
259 extern __inline__ int __lstat (__const char *__path, struct stat *__statbuf)
261 # ifndef __USE_FILE_OFFSET64
262 return __lxstat (_STAT_VER, __path, __statbuf);
263 # else
264 return __lxstat64 (_STAT_VER, __path, __statbuf);
265 # endif
267 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
268 extern __inline__ int lstat (__const char *__path, struct stat *__statbuf)
270 # ifndef __USE_FILE_OFFSET64
271 return __lxstat (_STAT_VER, __path, __statbuf);
272 # else
273 return __lxstat64 (_STAT_VER, __path, __statbuf);
274 # endif
276 # endif
278 extern __inline__ int __fstat (int __fd, struct stat *__statbuf)
280 # ifndef __USE_FILE_OFFSET64
281 return __fxstat (_STAT_VER, __fd, __statbuf);
282 # else
283 return __fxstat64 (_STAT_VER, __fd, __statbuf);
284 # endif
286 extern __inline__ int fstat (int __fd, struct stat *__statbuf)
288 # ifndef __USE_FILE_OFFSET64
289 return __fxstat (_STAT_VER, __fd, __statbuf);
290 # else
291 return __fxstat64 (_STAT_VER, __fd, __statbuf);
292 # endif
295 extern __inline__ int __mknod (__const char *__path, __mode_t __mode,
296 __dev_t __dev)
297 { return __xmknod (_MKNOD_VER, __path, __mode, &__dev); }
298 # if defined __USE_MISC || defined __USE_BSD
299 extern __inline__ int mknod (__const char *__path, __mode_t __mode,
300 __dev_t __dev)
301 { return __xmknod (_MKNOD_VER, __path, __mode, &__dev); }
302 # endif
304 # ifdef __USE_LARGEFILE64
305 extern __inline__ int stat64 (__const char *__path, struct stat64 *__statbuf)
307 return __xstat64 (_STAT_VER, __path, __statbuf);
310 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
311 extern __inline__ int lstat64 (__const char *__path, struct stat64 *__statbuf)
313 return __lxstat64 (_STAT_VER, __path, __statbuf);
315 # endif
317 extern __inline__ int fstat64 (int __fd, struct stat64 *__statbuf)
319 return __fxstat64 (_STAT_VER, __fd, __statbuf);
321 # endif
323 #endif
325 __END_DECLS
328 #endif /* sys/stat.h */