File: /usr/include/sys/stat.h

1     /* Copyright (C) 1991, 92, 1995-1999, 2000, 2001 Free Software Foundation, Inc.
2        This file is part of the GNU C Library.
3     
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.
8     
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.
13     
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.  */
18     
19     /*
20      *	POSIX Standard: 5.6 File Characteristics	<sys/stat.h>
21      */
22     
23     #ifndef	_SYS_STAT_H
24     #define	_SYS_STAT_H	1
25     
26     #include <features.h>
27     
28     #include <bits/types.h>		/* For __mode_t and __dev_t.  */
29     
30     #ifdef __USE_XOPEN
31     # define __need_time_t
32     # include <time.h>		/* For time_t.  */
33     
34     /* The Single Unix specification says that some more types are
35        available here.  */
36     # ifndef __dev_t_defined
37     typedef __dev_t dev_t;
38     #  define __dev_t_defined
39     # endif
40     
41     # ifndef __gid_t_defined
42     typedef __gid_t gid_t;
43     #  define __gid_t_defined
44     # endif
45     
46     # ifndef __ino_t_defined
47     #  ifndef __USE_FILE_OFFSET64
48     typedef __ino_t ino_t;
49     #  else
50     typedef __ino64_t ino_t;
51     #  endif
52     #  define __ino_t_defined
53     # endif
54     
55     # ifndef __mode_t_defined
56     typedef __mode_t mode_t;
57     #  define __mode_t_defined
58     # endif
59     
60     # ifndef __nlink_t_defined
61     typedef __nlink_t nlink_t;
62     #  define __nlink_t_defined
63     # endif
64     
65     # ifndef __off_t_defined
66     #  ifndef __USE_FILE_OFFSET64
67     typedef __off_t off_t;
68     #  else
69     typedef __off64_t off_t;
70     #  endif
71     #  define __off_t_defined
72     # endif
73     
74     # ifndef __uid_t_defined
75     typedef __uid_t uid_t;
76     #  define __uid_t_defined
77     # endif
78     #endif	/* X/Open */
79     
80     #ifdef __USE_UNIX98
81     # ifndef __blkcnt_t_defined
82     #  ifndef __USE_FILE_OFFSET64
83     typedef __blkcnt_t blkcnt_t;
84     #  else
85     typedef __blkcnt64_t blkcnt_t;
86     #  endif
87     #  define __blkcnt_t_defined
88     # endif
89     
90     # ifndef __blksize_t_defined
91     typedef __blksize_t blksize_t;
92     #  define __blksize_t_defined
93     # endif
94     #endif	/* Unix98 */
95     
96     __BEGIN_DECLS
97     
98     #include <bits/stat.h>
99     
100     #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
101     # define S_IFMT		__S_IFMT
102     # define S_IFDIR	__S_IFDIR
103     # define S_IFCHR	__S_IFCHR
104     # define S_IFBLK	__S_IFBLK
105     # define S_IFREG	__S_IFREG
106     # ifdef __S_IFIFO
107     #  define S_IFIFO	__S_IFIFO
108     # endif
109     # ifdef __S_IFLNK
110     #  define S_IFLNK	__S_IFLNK
111     # endif
112     # if (defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN2K) \
113          && defined __S_IFSOCK
114     #  define S_IFSOCK	__S_IFSOCK
115     # endif
116     #endif
117     
118     /* Test macros for file types.	*/
119     
120     #define	__S_ISTYPE(mode, mask)	(((mode) & __S_IFMT) == (mask))
121     
122     #define	S_ISDIR(mode)	 __S_ISTYPE((mode), __S_IFDIR)
123     #define	S_ISCHR(mode)	 __S_ISTYPE((mode), __S_IFCHR)
124     #define	S_ISBLK(mode)	 __S_ISTYPE((mode), __S_IFBLK)
125     #define	S_ISREG(mode)	 __S_ISTYPE((mode), __S_IFREG)
126     #ifdef __S_IFIFO
127     # define S_ISFIFO(mode)	 __S_ISTYPE((mode), __S_IFIFO)
128     #endif
129     #ifdef __S_IFLNK
130     # define S_ISLNK(mode)	 __S_ISTYPE((mode), __S_IFLNK)
131     #endif
132     
133     #ifdef	__USE_BSD
134     # ifndef __S_IFLNK
135     #  define S_ISLNK(mode)  0
136     # endif
137     # ifdef __S_IFSOCK
138     #  define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
139     # endif
140     #endif
141     
142     /* These are from POSIX.1b.  If the objects are not implemented using separate
143        distinct file types, the macros always will evaluate to zero.  Unlike the
144        other S_* macros the following three take a pointer to a `struct stat'
145        object as the argument.  */
146     #ifdef	__USE_POSIX199309
147     # define S_TYPEISMQ(buf) __S_TYPEISMQ(buf)
148     # define S_TYPEISSEM(buf) __S_TYPEISSEM(buf)
149     # define S_TYPEISSHM(buf) __S_TYPEISSHM(buf)
150     #endif
151     
152     
153     /* Protection bits.  */
154     
155     #define	S_ISUID __S_ISUID	/* Set user ID on execution.  */
156     #define	S_ISGID	__S_ISGID	/* Set group ID on execution.  */
157     
158     #if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN
159     /* Save swapped text after use (sticky bit).  This is pretty well obsolete.  */
160     # define S_ISVTX	__S_ISVTX
161     #endif
162     
163     #define	S_IRUSR	__S_IREAD	/* Read by owner.  */
164     #define	S_IWUSR	__S_IWRITE	/* Write by owner.  */
165     #define	S_IXUSR	__S_IEXEC	/* Execute by owner.  */
166     /* Read, write, and execute by owner.  */
167     #define	S_IRWXU	(__S_IREAD|__S_IWRITE|__S_IEXEC)
168     
169     #if defined __USE_MISC && defined __USE_BSD
170     # define S_IREAD	S_IRUSR
171     # define S_IWRITE	S_IWUSR
172     # define S_IEXEC	S_IXUSR
173     #endif
174     
175     #define	S_IRGRP	(S_IRUSR >> 3)	/* Read by group.  */
176     #define	S_IWGRP	(S_IWUSR >> 3)	/* Write by group.  */
177     #define	S_IXGRP	(S_IXUSR >> 3)	/* Execute by group.  */
178     /* Read, write, and execute by group.  */
179     #define	S_IRWXG	(S_IRWXU >> 3)
180     
181     #define	S_IROTH	(S_IRGRP >> 3)	/* Read by others.  */
182     #define	S_IWOTH	(S_IWGRP >> 3)	/* Write by others.  */
183     #define	S_IXOTH	(S_IXGRP >> 3)	/* Execute by others.  */
184     /* Read, write, and execute by others.  */
185     #define	S_IRWXO	(S_IRWXG >> 3)
186     
187     
188     #ifdef	__USE_BSD
189     /* Macros for common mode bit masks.  */
190     # define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
191     # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
192     # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
193     
194     # define S_BLKSIZE	512	/* Block size for `st_blocks'.  */
195     #endif
196     
197     
198     #ifndef __USE_FILE_OFFSET64
199     /* Get file attributes for FILE and put them in BUF.  */
200     extern int stat (__const char *__restrict __file,
201     		 struct stat *__restrict __buf) __THROW;
202     
203     /* Get file attributes for the file, device, pipe, or socket
204        that file descriptor FD is open on and put them in BUF.  */
205     extern int fstat (int __fd, struct stat *__buf) __THROW;
206     #else
207     # ifdef __REDIRECT
208     extern int __REDIRECT (stat,
209     		       (__const char *__restrict __file,
210     			struct stat *__restrict __buf) __THROW,
211     		       stat64);
212     extern int __REDIRECT (fstat, (int __fd, struct stat *__buf) __THROW, fstat64);
213     # else
214     #  define stat stat64
215     #  define fstat fstat64
216     # endif
217     #endif
218     #ifdef __USE_LARGEFILE64
219     extern int stat64 (__const char *__restrict __file,
220     		   struct stat64 *__restrict __buf) __THROW;
221     extern int fstat64 (int __fd, struct stat64 *__buf) __THROW;
222     #endif
223     
224     #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
225     # ifndef __USE_FILE_OFFSET64
226     /* Get file attributes about FILE and put them in BUF.
227        If FILE is a symbolic link, do not follow it.  */
228     extern int lstat (__const char *__restrict __file,
229     		  struct stat *__restrict __buf) __THROW;
230     # else
231     #  ifdef __REDIRECT
232     extern int __REDIRECT (lstat,
233     		       (__const char *__restrict __file,
234     			struct stat *__restrict __buf) __THROW,
235     		       lstat64);
236     #  else
237     #   define lstat lstat64
238     #  endif
239     # endif
240     # ifdef __USE_LARGEFILE64
241     extern int lstat64 (__const char *__restrict __file,
242     		    struct stat64 *__restrict __buf) __THROW;
243     # endif
244     #endif
245     
246     /* Set file access permissions for FILE to MODE.
247        This takes an `int' MODE argument because that
248        is what `mode_t's get widened to.  */
249     extern int chmod (__const char *__file, __mode_t __mode) __THROW;
250     
251     /* Set file access permissions of the file FD is open on to MODE.  */
252     #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
253     extern int fchmod (int __fd, __mode_t __mode) __THROW;
254     #endif
255     
256     
257     /* Set the file creation mask of the current process to MASK,
258        and return the old creation mask.  */
259     extern __mode_t umask (__mode_t __mask) __THROW;
260     
261     #ifdef	__USE_GNU
262     /* Get the current `umask' value without changing it.
263        This function is only available under the GNU Hurd.  */
264     extern __mode_t getumask (void) __THROW;
265     #endif
266     
267     /* Create a new directory named PATH, with permission bits MODE.  */
268     extern int mkdir (__const char *__path, __mode_t __mode) __THROW;
269     
270     /* Create a device file named PATH, with permission and special bits MODE
271        and device number DEV (which can be constructed from major and minor
272        device numbers with the `makedev' macro above).  */
273     #if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
274     extern int mknod (__const char *__path, __mode_t __mode, __dev_t __dev)
275          __THROW;
276     #endif
277     
278     
279     /* Create a new FIFO named PATH, with permission bits MODE.  */
280     extern int mkfifo (__const char *__path, __mode_t __mode) __THROW;
281     
282     /* To allow the `struct stat' structure and the file type `mode_t'
283        bits to vary without changing shared library major version number,
284        the `stat' family of functions and `mknod' are in fact inline
285        wrappers around calls to `xstat', `fxstat', `lxstat', and `xmknod',
286        which all take a leading version-number argument designating the
287        data structure and bits used.  <bits/stat.h> defines _STAT_VER with
288        the version number corresponding to `struct stat' as defined in
289        that file; and _MKNOD_VER with the version number corresponding to
290        the S_IF* macros defined therein.  It is arranged that when not
291        inlined these function are always statically linked; that way a
292        dynamically-linked executable always encodes the version number
293        corresponding to the data structures it uses, so the `x' functions
294        in the shared library can adapt without needing to recompile all
295        callers.  */
296     
297     #ifndef _STAT_VER
298     # define _STAT_VER	0
299     #endif
300     #ifndef _MKNOD_VER
301     # define _MKNOD_VER	0
302     #endif
303     
304     /* Wrappers for stat and mknod system calls.  */
305     #ifndef __USE_FILE_OFFSET64
306     extern int __fxstat (int __ver, int __fildes, struct stat *__stat_buf) __THROW;
307     extern int __xstat (int __ver, __const char *__filename,
308     		    struct stat *__stat_buf) __THROW;
309     extern int __lxstat (int __ver, __const char *__filename,
310     		     struct stat *__stat_buf) __THROW;
311     #else
312     # ifdef __REDIRECT
313     extern int __REDIRECT (__fxstat, (int __ver, int __fildes,
314     				  struct stat *__stat_buf) __THROW,
315     		       __fxstat64);
316     extern int __REDIRECT (__xstat, (int __ver, __const char *__filename,
317     				 struct stat *__stat_buf) __THROW, __xstat64);
318     extern int __REDIRECT (__lxstat, (int __ver, __const char *__filename,
319     				  struct stat *__stat_buf) __THROW,
320     		       __lxstat64);
321     
322     # else
323     #  define __fxstat __fxstat64
324     #  define __xstat __xstat64
325     #  define __lxstat __lxstat64
326     # endif
327     #endif
328     
329     #ifdef __USE_LARGEFILE64
330     extern int __fxstat64 (int __ver, int __fildes, struct stat64 *__stat_buf)
331          __THROW;
332     extern int __xstat64 (int __ver, __const char *__filename,
333     		      struct stat64 *__stat_buf) __THROW;
334     extern int __lxstat64 (int __ver, __const char *__filename,
335     		       struct stat64 *__stat_buf) __THROW;
336     #endif
337     extern int __xmknod (int __ver, __const char *__path, __mode_t __mode,
338     		     __dev_t *__dev) __THROW;
339     
340     #if defined __GNUC__ && __GNUC__ >= 2
341     /* Inlined versions of the real stat and mknod functions.  */
342     
343     extern __inline__ int stat (__const char *__path,
344     			    struct stat *__statbuf) __THROW
345     {
346       return __xstat (_STAT_VER, __path, __statbuf);
347     }
348     
349     # if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
350     extern __inline__ int lstat (__const char *__path,
351     			     struct stat *__statbuf) __THROW
352     {
353       return __lxstat (_STAT_VER, __path, __statbuf);
354     }
355     # endif
356     
357     extern __inline__ int fstat (int __fd, struct stat *__statbuf) __THROW
358     {
359       return __fxstat (_STAT_VER, __fd, __statbuf);
360     }
361     
362     # if defined __USE_MISC || defined __USE_BSD
363     extern __inline__ int mknod (__const char *__path, __mode_t __mode,
364     			     __dev_t __dev) __THROW
365     {
366       return __xmknod (_MKNOD_VER, __path, __mode, &__dev);
367     }
368     # endif
369     
370     # if defined __USE_LARGEFILE64 \
371       && (! defined __USE_FILE_OFFSET64 \
372           || (defined __REDIRECT && defined __OPTIMIZE__))
373     extern __inline__ int stat64 (__const char *__path,
374     			      struct stat64 *__statbuf) __THROW
375     {
376       return __xstat64 (_STAT_VER, __path, __statbuf);
377     }
378     
379     #  if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
380     extern __inline__ int lstat64 (__const char *__path,
381     			       struct stat64 *__statbuf) __THROW
382     {
383       return __lxstat64 (_STAT_VER, __path, __statbuf);
384     }
385     #  endif
386     
387     extern __inline__ int fstat64 (int __fd, struct stat64 *__statbuf) __THROW
388     {
389       return __fxstat64 (_STAT_VER, __fd, __statbuf);
390     }
391     # endif
392     
393     #endif
394     
395     __END_DECLS
396     
397     
398     #endif /* sys/stat.h  */
399