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 # define __need_time_t
32 # include <time.h> /* For time_t. */
34 /* The Single Unix specification says that some more types are
37 typedef __dev_t dev_t
;
42 typedef __gid_t gid_t
;
47 # ifndef __USE_FILE_OFFSET64
48 typedef __ino_t ino_t
;
50 typedef __ino64_t ino_t
;
56 typedef __mode_t mode_t
;
57 # define mode_t mode_t
61 typedef __nlink_t nlink_t
;
62 # define nlink_t nlink_t
66 # ifndef __USE_FILE_OFFSET64
67 typedef __off_t off_t
;
69 typedef __off64_t off_t
;
75 typedef __uid_t uid_t
;
82 typedef __pid_t pid_t
;
89 #include <bits/stat.h>
91 #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
92 # define S_IFMT __S_IFMT
93 # define S_IFDIR __S_IFDIR
94 # define S_IFCHR __S_IFCHR
95 # define S_IFBLK __S_IFBLK
96 # define S_IFREG __S_IFREG
98 # define S_IFIFO __S_IFIFO
100 # if defined __USE_BSD || defined __USE_MISC
102 # define S_IFLNK __S_IFLNK
105 # define S_IFSOCK __S_IFSOCK
110 /* Test macros for file types. */
112 #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
114 #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
115 #define S_ISCHR(mode) __S_ISTYPE((mode), __S_IFCHR)
116 #define S_ISBLK(mode) __S_ISTYPE((mode), __S_IFBLK)
117 #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
119 # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
124 # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
126 # define S_ISLNK(mode) 0
129 # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
134 /* Protection bits. */
136 #define S_ISUID __S_ISUID /* Set user ID on execution. */
137 #define S_ISGID __S_ISGID /* Set group ID on execution. */
139 #if defined __USE_BSD || defined __USE_MISC
140 /* Save swapped text after use (sticky bit). This is pretty well obsolete. */
141 # define S_ISVTX __S_ISVTX
144 #define S_IRUSR __S_IREAD /* Read by owner. */
145 #define S_IWUSR __S_IWRITE /* Write by owner. */
146 #define S_IXUSR __S_IEXEC /* Execute by owner. */
147 /* Read, write, and execute by owner. */
148 #define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
150 #if defined __USE_MISC && defined __USE_BSD
151 # define S_IREAD S_IRUSR
152 # define S_IWRITE S_IWUSR
153 # define S_IEXEC S_IXUSR
156 #define S_IRGRP (S_IRUSR >> 3) /* Read by group. */
157 #define S_IWGRP (S_IWUSR >> 3) /* Write by group. */
158 #define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */
159 /* Read, write, and execute by group. */
160 #define S_IRWXG (S_IRWXU >> 3)
162 #define S_IROTH (S_IRGRP >> 3) /* Read by others. */
163 #define S_IWOTH (S_IWGRP >> 3) /* Write by others. */
164 #define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */
165 /* Read, write, and execute by others. */
166 #define S_IRWXO (S_IRWXG >> 3)
170 /* Macros for common mode bit masks. */
171 # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
172 # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
173 # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
175 # define S_BLKSIZE 512 /* Block size for `st_blocks'. */
179 #ifndef __USE_FILE_OFFSET64
180 /* Get file attributes for FILE and put them in BUF. */
181 extern int stat
__P ((__const
char *__file
, struct stat
*__buf
));
183 /* Get file attributes for the file, device, pipe, or socket
184 that file descriptor FD is open on and put them in BUF. */
185 extern int fstat
__P ((int __fd
, struct stat
*__buf
));
188 extern int __REDIRECT (stat
, __P ((__const
char *__file
, struct stat
*__buf
)),
190 extern int __REDIRECT (fstat
, __P ((int __fd
, struct stat
*__buf
)), fstat64
);
193 # define fstat fstat64
196 #ifdef __USE_LARGEFILE64
197 extern int stat64
__P ((__const
char *__file
, struct stat64
*__buf
));
198 extern int fstat64
__P ((int __fd
, struct stat64
*__buf
));
201 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
202 # ifndef __USE_FILE_OFFSET64
203 /* Get file attributes about FILE and put them in BUF.
204 If FILE is a symbolic link, do not follow it. */
205 extern int lstat
__P ((__const
char *__file
, struct stat
*__buf
));
208 extern int __REDIRECT (lstat
, __P ((__const
char *__file
, struct stat
*__buf
)),
211 # define lstat lstat64
214 # ifdef __USE_LARGEFILE64
215 extern int lstat64
__P ((__const
char *__file
, struct stat64
*__buf
));
219 /* Set file access permissions for FILE to MODE.
220 This takes an `int' MODE argument because that
221 is what `mode_t's get widened to. */
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 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
226 extern int fchmod
__P ((int __fd
, __mode_t __mode
));
230 /* Set the file creation mask of the current process to MASK,
231 and return the old creation mask. */
232 extern __mode_t umask
__P ((__mode_t __mask
));
235 /* Get the current `umask' value without changing it.
236 This function is only available under the GNU Hurd. */
237 extern __mode_t getumask
__P ((void));
240 /* Create a new directory named PATH, with permission bits MODE. */
241 extern int mkdir
__P ((__const
char *__path
, __mode_t __mode
));
243 /* Create a device file named PATH, with permission and special bits MODE
244 and device number DEV (which can be constructed from major and minor
245 device numbers with the `makedev' macro above). */
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
));
252 /* Create a new FIFO named PATH, with permission bits MODE. */
253 extern int mkfifo
__P ((__const
char *__path
, __mode_t __mode
));
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
274 # define _MKNOD_VER 0
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
));
287 extern int __REDIRECT (__fxstat
, __P ((int __ver
, int __fildes
,
288 struct stat
*__stat_buf
)), __fxstat64
);
289 extern int __REDIRECT (__xstat
, __P ((int __ver
, __const
char *__filename
,
290 struct stat
*__stat_buf
)), __xstat64
);
291 extern int __REDIRECT (__lxstat
, __P ((int __ver
, __const
char *__filename
,
292 struct stat
*__stat_buf
)), __lxstat64
);
295 # define __fxstat __fxstat64
296 # define __xstat __xstat64
297 # define __lxstat __lxstat64
301 #ifdef __USE_LARGEFILE64
302 extern int __fxstat64
__P ((int __ver
, int __fildes
,
303 struct stat64
*__stat_buf
));
304 extern int __xstat64
__P ((int __ver
, __const
char *__filename
,
305 struct stat64
*__stat_buf
));
306 extern int __lxstat64
__P ((int __ver
, __const
char *__filename
,
307 struct stat64
*__stat_buf
));
309 extern int __xmknod
__P ((int __ver
, __const
char *__path
,
310 __mode_t __mode
, __dev_t
*__dev
));
312 #if defined __GNUC__ && __GNUC__ >= 2
313 /* Inlined versions of the real stat and mknod functions. */
315 extern __inline__
int stat (__const
char *__path
, struct stat
*__statbuf
)
317 return __xstat (_STAT_VER
, __path
, __statbuf
);
320 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
321 extern __inline__
int lstat (__const
char *__path
, struct stat
*__statbuf
)
323 return __lxstat (_STAT_VER
, __path
, __statbuf
);
327 extern __inline__
int fstat (int __fd
, struct stat
*__statbuf
)
329 return __fxstat (_STAT_VER
, __fd
, __statbuf
);
332 # if defined __USE_MISC || defined __USE_BSD
333 extern __inline__
int mknod (__const
char *__path
, __mode_t __mode
,
336 return __xmknod (_MKNOD_VER
, __path
, __mode
, &__dev
);
340 # ifdef __USE_LARGEFILE64
341 extern __inline__
int stat64 (__const
char *__path
, struct stat64
*__statbuf
)
343 return __xstat64 (_STAT_VER
, __path
, __statbuf
);
346 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
347 extern __inline__
int lstat64 (__const
char *__path
, struct stat64
*__statbuf
)
349 return __lxstat64 (_STAT_VER
, __path
, __statbuf
);
353 extern __inline__
int fstat64 (int __fd
, struct stat64
*__statbuf
)
355 return __fxstat64 (_STAT_VER
, __fd
, __statbuf
);
364 #endif /* sys/stat.h */