1 /* Copyright (C) 1991, 92, 95, 96, 97, 98 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>
28 #include <bits/types.h> /* For __mode_t and __dev_t. */
31 /* The Single Unix specification says that some more types are
34 typedef __dev_t dev_t;
39 typedef __gid_t gid_t;
44 # ifndef __USE_FILE_OFFSET64
45 typedef __ino_t ino_t;
47 typedef __ino64_t ino_t;
53 typedef __mode_t mode_t;
54 # define mode_t mode_t
58 typedef __nlink_t nlink_t;
59 # define nlink_t nlink_t
63 # ifndef __USE_FILE_OFFSET64
64 typedef __off_t off_t;
66 typedef __off64_t off_t;
72 typedef __uid_t uid_t;
77 typedef __pid_t pid_t;
84 #include <bits/stat.h>
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
93 # define S_IFIFO __S_IFIFO
95 # if defined __USE_BSD || defined __USE_MISC
97 # define S_IFLNK __S_IFLNK
100 # define S_IFSOCK __S_IFSOCK
105 /* Test macros for file types. */
107 #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
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)
114 # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
119 # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
121 # define S_ISLNK(mode) 0
124 # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
129 /* Protection bits. */
131 #define S_ISUID __S_ISUID /* Set user ID on execution. */
132 #define S_ISGID __S_ISGID /* Set group ID on execution. */
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
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)
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
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)
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)
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*/
170 # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
174 /* Get file attributes for FILE and put them in BUF. */
175 extern int __stat __P ((__const char *__file, struct stat *__buf));
176 /* Get file attributes for the file, device, pipe, or socket
177 that file descriptor FD is open on and put them in BUF. */
178 extern int __fstat __P ((int __fd, struct stat *__buf));
179 /* Get file attributes about FILE and put them in BUF.
180 If FILE is a symbolic link, do not follow it. */
181 extern int __lstat __P ((__const char *__file, struct stat *__buf));
184 #ifndef __USE_FILE_OFFSET64
185 extern int stat __P ((__const char *__file, struct stat *__buf));
186 extern int fstat __P ((int __fd, struct stat *__buf));
189 extern int __REDIRECT (stat, __P ((__const char *__file, struct stat *__buf)),
191 extern int __REDIRECT (fstat, __P ((int __fd, struct stat *__buf)), fstat64);
194 # define fstat fstat64
197 #ifdef __USE_LARGEFILE64
198 extern int stat64 __P ((__const char *__file, struct stat64 *__buf));
199 extern int fstat64 __P ((int __fd, struct stat64 *__buf));
202 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
203 # ifndef __USE_FILE_OFFSET64
204 extern int lstat __P ((__const char *__file, struct stat *__buf));
207 extern int __REDIRECT (lstat, __P ((__const char *__file, struct stat *__buf)),
210 # define lstat lstat64
213 # ifdef __USE_LARGEFILE64
214 extern int lstat64 __P ((__const char *__file, struct stat64 *__buf));
218 /* Set file access permissions for FILE to MODE.
219 This takes an `int' MODE argument because that
220 is what `mode_t's get widened to. */
221 extern int __chmod __P ((__const char *__file, __mode_t __mode));
222 extern int chmod __P ((__const char *__file, __mode_t __mode));
224 /* Set file access permissions of the file FD is open on to MODE. */
225 extern int __fchmod __P ((int __fd, __mode_t __mode));
226 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
227 extern int fchmod __P ((int __fd, __mode_t __mode));
231 /* Set the file creation mask of the current process to MASK,
232 and return the old creation mask. */
233 extern __mode_t __umask __P ((__mode_t __mask));
234 extern __mode_t umask __P ((__mode_t __mask));
237 /* Get the current `umask' value without changing it.
238 This function is only available under the GNU Hurd. */
239 extern __mode_t getumask __P ((void));
242 /* Create a new directory named PATH, with permission bits MODE. */
243 extern int __mkdir __P ((__const char *__path, __mode_t __mode));
244 extern int mkdir __P ((__const char *__path, __mode_t __mode));
246 /* Create a device file named PATH, with permission and special bits MODE
247 and device number DEV (which can be constructed from major and minor
248 device numbers with the `makedev' macro above). */
249 extern int __mknod __P ((__const char *__path,
250 __mode_t __mode, __dev_t __dev));
251 #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
252 extern int mknod __P ((__const char *__path,
253 __mode_t __mode, __dev_t __dev));
257 /* Create a new FIFO named PATH, with permission bits MODE. */
258 extern int mkfifo __P ((__const char *__path, __mode_t __mode));
260 /* To allow the `struct stat' structure and the file type `mode_t'
261 bits to vary without changing shared library major version number,
262 the `stat' family of functions and `mknod' are in fact inline
263 wrappers around calls to `xstat', `fxstat', `lxstat', and `xmknod',
264 which all take a leading version-number argument designating the
265 data structure and bits used. <bits/stat.h> defines _STAT_VER with
266 the version number corresponding to `struct stat' as defined in
267 that file; and _MKNOD_VER with the version number corresponding to
268 the S_IF* macros defined therein. It is arranged that when not
269 inlined these function are always statically linked; that way a
270 dynamically-linked executable always encodes the version number
271 corresponding to the data structures it uses, so the `x' functions
272 in the shared library can adapt without needing to recompile all
279 # define _MKNOD_VER 0
282 /* Wrappers for stat and mknod system calls. */
283 #ifndef __USE_FILE_OFFSET64
284 extern int __fxstat __P ((int __ver, int __fildes,
285 struct stat *__stat_buf));
286 extern int __xstat __P ((int __ver, __const char *__filename,
287 struct stat *__stat_buf));
288 extern int __lxstat __P ((int __ver, __const char *__filename,
289 struct stat *__stat_buf));
292 extern int __REDIRECT (__fxstat, __P ((int __ver, int __fildes,
293 struct stat *__stat_buf)), __fxstat64);
294 extern int __REDIRECT (__xstat, __P ((int __ver, __const char *__filename,
295 struct stat *__stat_buf)), __xstat64);
296 extern int __REDIRECT (__lxstat, __P ((int __ver, __const char *__filename,
297 struct stat *__stat_buf)), __lxstat64);
300 # define __fxstat __fxstat64
301 # define __xstat __xstat64
302 # define __lxstat __lxstat64
306 #ifdef __USE_LARGEFILE64
307 extern int __fxstat64 __P ((int __ver, int __fildes,
308 struct stat64 *__stat_buf));
309 extern int __xstat64 __P ((int __ver, __const char *__filename,
310 struct stat64 *__stat_buf));
311 extern int __lxstat64 __P ((int __ver, __const char *__filename,
312 struct stat64 *__stat_buf));
314 extern int __xmknod __P ((int __ver, __const char *__path,
315 __mode_t __mode, __dev_t *__dev));
317 #if defined __GNUC__ && __GNUC__ >= 2
318 /* Inlined versions of the real stat and mknod functions. */
320 extern __inline__ int __stat (__const char *__path, struct stat *__statbuf)
322 return __xstat (_STAT_VER, __path, __statbuf);
324 extern __inline__ int stat (__const char *__path, struct stat *__statbuf)
326 return __xstat (_STAT_VER, __path, __statbuf);
329 extern __inline__ int __lstat (__const char *__path, struct stat *__statbuf)
331 return __lxstat (_STAT_VER, __path, __statbuf);
333 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
334 extern __inline__ int lstat (__const char *__path, struct stat *__statbuf)
336 return __lxstat (_STAT_VER, __path, __statbuf);
340 extern __inline__ int __fstat (int __fd, struct stat *__statbuf)
342 return __fxstat (_STAT_VER, __fd, __statbuf);
344 extern __inline__ int fstat (int __fd, struct stat *__statbuf)
346 return __fxstat (_STAT_VER, __fd, __statbuf);
349 extern __inline__ int __mknod (__const char *__path, __mode_t __mode,
351 { return __xmknod (_MKNOD_VER, __path, __mode, &__dev); }
352 # if defined __USE_MISC || defined __USE_BSD
353 extern __inline__ int mknod (__const char *__path, __mode_t __mode,
355 { return __xmknod (_MKNOD_VER, __path, __mode, &__dev); }
358 # ifdef __USE_LARGEFILE64
359 extern __inline__ int stat64 (__const char *__path, struct stat64 *__statbuf)
361 return __xstat64 (_STAT_VER, __path, __statbuf);
364 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
365 extern __inline__ int lstat64 (__const char *__path, struct stat64 *__statbuf)
367 return __lxstat64 (_STAT_VER, __path, __statbuf);
371 extern __inline__ int fstat64 (int __fd, struct stat64 *__statbuf)
373 return __fxstat64 (_STAT_VER, __fd, __statbuf);
382 #endif /* sys/stat.h */