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. */
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
41 # define S_IFLNK __S_IFLNK
44 # define S_IFSOCK __S_IFSOCK
47 # define S_IFIFO __S_IFIFO
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)
60 # define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFIFO)
65 # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
68 # define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
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
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
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)
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'. */
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
));
123 extern int stat
__P ((__const
char *__file
, struct stat
*__buf
))
126 #ifdef __USE_LARGEFILE64
127 extern int stat64
__P ((__const
char *__file
, struct stat64
*__buf
));
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
));
136 extern int fstat
__P ((int __fd
, struct stat
*__buf
)) __asm__ ("fstat64");
138 #ifdef __USE_LARGEFILE64
139 extern int fstat64
__P ((int __fd
, struct stat64
*__buf
));
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
));
149 extern int lstat
__P ((__const
char *__file
, struct stat
*__buf
))
152 # ifdef __USE_LARGEFILE64
153 extern int lstat64
__P ((__const
char *__file
, struct stat64
*__buf
));
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
));
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
));
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));
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
));
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
218 # define _MKNOD_VER 0
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
));
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
);
247 return __xstat64 (_STAT_VER
, __path
, __statbuf
);
250 extern __inline__
int stat (__const
char *__path
, struct stat
*__statbuf
)
252 # ifndef __USE_FILE_OFFSET64
253 return __xstat (_STAT_VER
, __path
, __statbuf
);
255 return __xstat64 (_STAT_VER
, __path
, __statbuf
);
259 extern __inline__
int __lstat (__const
char *__path
, struct stat
*__statbuf
)
261 # ifndef __USE_FILE_OFFSET64
262 return __lxstat (_STAT_VER
, __path
, __statbuf
);
264 return __lxstat64 (_STAT_VER
, __path
, __statbuf
);
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
);
273 return __lxstat64 (_STAT_VER
, __path
, __statbuf
);
278 extern __inline__
int __fstat (int __fd
, struct stat
*__statbuf
)
280 # ifndef __USE_FILE_OFFSET64
281 return __fxstat (_STAT_VER
, __fd
, __statbuf
);
283 return __fxstat64 (_STAT_VER
, __fd
, __statbuf
);
286 extern __inline__
int fstat (int __fd
, struct stat
*__statbuf
)
288 # ifndef __USE_FILE_OFFSET64
289 return __fxstat (_STAT_VER
, __fd
, __statbuf
);
291 return __fxstat64 (_STAT_VER
, __fd
, __statbuf
);
295 extern __inline__
int __mknod (__const
char *__path
, __mode_t __mode
,
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
,
301 { return __xmknod (_MKNOD_VER
, __path
, __mode
, &__dev
); }
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
);
317 extern __inline__
int fstat64 (int __fd
, struct stat64
*__statbuf
)
319 return __fxstat64 (_STAT_VER
, __fd
, __statbuf
);
328 #endif /* sys/stat.h */