1 /* Copyright (C) 1991, 1992, 1995, 1996 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
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
20 * POSIX Standard: 5.6 File Characteristics <sys/stat.h>
28 #include <gnu/types.h> /* For __mode_t and __dev_t. */
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 extern int stat
__P ((__const
char *__file
, struct stat
*__buf
));
122 /* Get file attributes for the file, device, pipe, or socket
123 that file descriptor FD is open on and put them in BUF. */
124 extern int __fstat
__P ((int __fd
, struct stat
*__buf
));
125 extern int fstat
__P ((int __fd
, struct stat
*__buf
));
127 /* Get file attributes about FILE and put them in BUF.
128 If FILE is a symbolic link, do not follow it. */
129 extern int __lstat
__P ((__const
char *__file
, struct stat
*__buf
));
131 extern int lstat
__P ((__const
char *__file
, struct stat
*__buf
));
134 /* Set file access permissions for FILE to MODE.
135 This takes an `int' MODE argument because that
136 is what `mode_t's get widened to. */
137 extern int __chmod
__P ((__const
char *__file
, __mode_t __mode
));
138 extern int chmod
__P ((__const
char *__file
, __mode_t __mode
));
140 /* Set file access permissions of the file FD is open on to MODE. */
141 extern int __fchmod
__P ((int __fd
, __mode_t __mode
));
143 extern int fchmod
__P ((int __fd
, __mode_t __mode
));
147 /* Set the file creation mask of the current process to MASK,
148 and return the old creation mask. */
149 extern __mode_t __umask
__P ((__mode_t __mask
));
150 extern __mode_t umask
__P ((__mode_t __mask
));
153 /* Get the current `umask' value without changing it.
154 This function is only available under the GNU Hurd. */
155 extern __mode_t getumask
__P ((void));
158 /* Create a new directory named PATH, with permission bits MODE. */
159 extern int __mkdir
__P ((__const
char *__path
, __mode_t __mode
));
160 extern int mkdir
__P ((__const
char *__path
, __mode_t __mode
));
162 /* Create a device file named PATH, with permission and special bits MODE
163 and device number DEV (which can be constructed from major and minor
164 device numbers with the `makedev' macro above). */
165 extern int __mknod
__P ((__const
char *__path
,
166 __mode_t __mode
, __dev_t __dev
));
167 #if defined(__USE_MISC) || defined(__USE_BSD)
168 extern int mknod
__P ((__const
char *__path
,
169 __mode_t __mode
, __dev_t __dev
));
173 /* Create a new FIFO named PATH, with permission bits MODE. */
174 extern int mkfifo
__P ((__const
char *__path
, __mode_t __mode
));
176 /* To allow the `struct stat' structure and the file type `mode_t' bits to
177 vary without changing shared library major version number, the `stat'
178 family of functions and `mknod' are in fact inline wrappers around calls
179 to `xstat', `fxstat', `lxstat', and `xmknod', which all take a leading
180 version-number argument designating the data structure and bits used.
181 <statbuf.h> defines _STAT_VER with the version number corresponding to
182 `struct stat' as defined in that file; and _MKNOD_VER with the version
183 number corresponding to the S_IF* macros defined therein. It is
184 arranged that when not inlined these function are always statically
185 linked; that way a dynamically-linked executable always encodes the
186 version number corresponding to the data structures it uses, so the `x'
187 functions in the shared library can adapt without needing to recompile
197 /* Wrappers for stat and mknod system calls. */
198 extern int __fxstat
__P ((int __ver
, int __fildes
,
199 struct stat
*__stat_buf
));
200 extern int __xstat
__P ((int __ver
, __const
char *__filename
,
201 struct stat
*__stat_buf
));
202 extern int __lxstat
__P ((int __ver
, __const
char *__filename
,
203 struct stat
*__stat_buf
));
204 extern int __xmknod
__P ((int __ver
, __const
char *__path
,
205 __mode_t __mode
, __dev_t
*__dev
));
207 #if defined (__GNUC__) && __GNUC__ >= 2
208 /* Inlined versions of the real stat and mknod functions. */
210 extern __inline__
int __stat (__const
char *__path
, struct stat
*__statbuf
)
211 { return __xstat (_STAT_VER
, __path
, __statbuf
); }
212 extern __inline__
int stat (__const
char *__path
, struct stat
*__statbuf
)
213 { return __xstat (_STAT_VER
, __path
, __statbuf
); }
215 extern __inline__
int __lstat(__const
char *__path
, struct stat
*__statbuf
)
216 { return __lxstat (_STAT_VER
, __path
, __statbuf
); }
217 extern __inline__
int lstat(__const
char *__path
, struct stat
*__statbuf
)
218 { return __lxstat (_STAT_VER
, __path
, __statbuf
); }
220 extern __inline__
int __fstat (int __fd
, struct stat
*__statbuf
)
221 { return __fxstat (_STAT_VER
, __fd
, __statbuf
); }
222 extern __inline__
int fstat (int __fd
, struct stat
*__statbuf
)
223 { return __fxstat (_STAT_VER
, __fd
, __statbuf
); }
225 extern __inline__
int __mknod (__const
char *__path
, __mode_t __mode
,
227 { return __xmknod (_MKNOD_VER
, __path
, __mode
, &__dev
); }
228 #if defined(__USE_MISC) || defined(__USE_BSD)
229 extern __inline__
int mknod (__const
char *__path
, __mode_t __mode
,
231 { return __xmknod (_MKNOD_VER
, __path
, __mode
, &__dev
); }
239 #endif /* sys/stat.h */