]>
git.ipfire.org Git - thirdparty/glibc.git/blob - 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.
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
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 #ifndef __USE_FILE_OFFSET64
177 extern int stat
__P ((__const
char *__file
, struct stat
*__buf
));
179 extern int stat
__P ((__const
char *__file
, struct stat
*__buf
))
182 #ifdef __USE_LARGEFILE64
183 extern int stat64
__P ((__const
char *__file
, struct stat64
*__buf
));
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
));
192 extern int fstat
__P ((int __fd
, struct stat
*__buf
)) __asm__ ("fstat64");
194 #ifdef __USE_LARGEFILE64
195 extern int fstat64
__P ((int __fd
, struct stat64
*__buf
));
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
));
205 extern int lstat
__P ((__const
char *__file
, struct stat
*__buf
))
208 # ifdef __USE_LARGEFILE64
209 extern int lstat64
__P ((__const
char *__file
, struct stat64
*__buf
));
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
));
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
));
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
));
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));
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
));
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
));
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
));
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");
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
));
304 extern int __xmknod
__P ((int __ver
, __const
char *__path
,
305 __mode_t __mode
, __dev_t
*__dev
));
307 #if defined __GNUC__ && __GNUC__ >= 2
308 /* Inlined versions of the real stat and mknod functions. */
310 extern __inline__
int __stat (__const
char *__path
, struct stat
*__statbuf
)
312 return __xstat (_STAT_VER
, __path
, __statbuf
);
314 extern __inline__
int stat (__const
char *__path
, struct stat
*__statbuf
)
316 return __xstat (_STAT_VER
, __path
, __statbuf
);
319 extern __inline__
int __lstat (__const
char *__path
, struct stat
*__statbuf
)
321 return __lxstat (_STAT_VER
, __path
, __statbuf
);
323 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
324 extern __inline__
int lstat (__const
char *__path
, struct stat
*__statbuf
)
326 return __lxstat (_STAT_VER
, __path
, __statbuf
);
330 extern __inline__
int __fstat (int __fd
, struct stat
*__statbuf
)
332 return __fxstat (_STAT_VER
, __fd
, __statbuf
);
334 extern __inline__
int fstat (int __fd
, struct stat
*__statbuf
)
336 return __fxstat (_STAT_VER
, __fd
, __statbuf
);
339 extern __inline__
int __mknod (__const
char *__path
, __mode_t __mode
,
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
,
345 { return __xmknod (_MKNOD_VER
, __path
, __mode
, &__dev
); }
348 # ifdef __USE_LARGEFILE64
349 extern __inline__
int stat64 (__const
char *__path
, struct stat64
*__statbuf
)
351 return __xstat64 (_STAT_VER
, __path
, __statbuf
);
354 # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
355 extern __inline__
int lstat64 (__const
char *__path
, struct stat64
*__statbuf
)
357 return __lxstat64 (_STAT_VER
, __path
, __statbuf
);
361 extern __inline__
int fstat64 (int __fd
, struct stat64
*__statbuf
)
363 return __fxstat64 (_STAT_VER
, __fd
, __statbuf
);
372 #endif /* sys/stat.h */