(FILE_TYPE_H): Guard entire contents with #ifndef.
[gnulib.git] / lib / file-type.h
1 /* Return a string describing the type of a file.
2
3    Copyright (C) 1993, 1994, 2001, 2002 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software Foundation,
17    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18
19 /* Written by Paul Eggert and Jim Meyering.  */
20
21 /* Include <sys/types.h> and <sys/stat.h> before including this
22    file.  */
23
24 #ifndef FILE_TYPE_H
25 # define FILE_TYPE_H 1
26
27 # if 2 <= __GLIBC__ && 2 <= __GLIBC_MINOR__
28 #  if !defined _SYS_STAT_H || !defined _SYS_TYPES_H
29 you must include <sys/types.h> and <sys/stat.h> before including this file
30 #  endif
31 # endif
32
33 char const *file_type (struct stat const *);
34
35 # ifndef S_IFMT
36 #  define S_IFMT 0170000
37 # endif
38
39 # if STAT_MACROS_BROKEN
40 #  undef S_ISBLK
41 #  undef S_ISCHR
42 #  undef S_ISDIR
43 #  undef S_ISDOOR
44 #  undef S_ISFIFO
45 #  undef S_ISLNK
46 #  undef S_ISNAM
47 #  undef S_ISMPB
48 #  undef S_ISMPC
49 #  undef S_ISNWK
50 #  undef S_ISREG
51 #  undef S_ISSOCK
52 # endif
53
54
55 # ifndef S_ISBLK
56 #  ifdef S_IFBLK
57 #   define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
58 #  else
59 #   define S_ISBLK(m) 0
60 #  endif
61 # endif
62
63 # ifndef S_ISCHR
64 #  ifdef S_IFCHR
65 #   define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
66 #  else
67 #   define S_ISCHR(m) 0
68 #  endif
69 # endif
70
71 # ifndef S_ISDIR
72 #  ifdef S_IFDIR
73 #   define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
74 #  else
75 #   define S_ISDIR(m) 0
76 #  endif
77 # endif
78
79 # ifndef S_ISDOOR /* Solaris 2.5 and up */
80 #  ifdef S_IFDOOR
81 #   define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR)
82 #  else
83 #   define S_ISDOOR(m) 0
84 #  endif
85 # endif
86
87 # ifndef S_ISFIFO
88 #  ifdef S_IFIFO
89 #   define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
90 #  else
91 #   define S_ISFIFO(m) 0
92 #  endif
93 # endif
94
95 # ifndef S_ISLNK
96 #  ifdef S_IFLNK
97 #   define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
98 #  else
99 #   define S_ISLNK(m) 0
100 #  endif
101 # endif
102
103 # ifndef S_ISMPB /* V7 */
104 #  ifdef S_IFMPB
105 #   define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
106 #   define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
107 #  else
108 #   define S_ISMPB(m) 0
109 #   define S_ISMPC(m) 0
110 #  endif
111 # endif
112
113 # ifndef S_ISNAM /* Xenix */
114 #  ifdef S_IFNAM
115 #   define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
116 #  else
117 #   define S_ISNAM(m) 0
118 #  endif
119 # endif
120
121 # ifndef S_ISNWK /* HP/UX */
122 #  ifdef S_IFNWK
123 #   define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
124 #  else
125 #   define S_ISNWK(m) 0
126 #  endif
127 # endif
128
129 # ifndef S_ISREG
130 #  ifdef S_IFREG
131 #   define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
132 #  else
133 #   define S_ISREG(m) 0
134 #  endif
135 # endif
136
137 # ifndef S_ISSOCK
138 #  ifdef S_IFSOCK
139 #   define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
140 #  else
141 #   define S_ISSOCK(m) 0
142 #  endif
143 # endif
144
145
146 # ifndef S_TYPEISSEM
147 #  ifdef S_INSEM
148 #   define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
149 #  else
150 #   define S_TYPEISSEM(p) 0
151 #  endif
152 # endif
153
154 # ifndef S_TYPEISSHM
155 #  ifdef S_INSHD
156 #   define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
157 #  else
158 #   define S_TYPEISSHM(p) 0
159 #  endif
160 # endif
161
162 # ifndef S_TYPEISMQ
163 #  define S_TYPEISMQ(p) 0
164 # endif
165
166 #endif /* FILE_TYPE_H */