5a83c7549716b7c260395a0907456768e3f99f04
[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 char const *file_type (struct stat const *);
25
26 #ifndef S_IFMT
27 # define S_IFMT 0170000
28 #endif
29
30 #if STAT_MACROS_BROKEN
31 # undef S_ISBLK
32 # undef S_ISCHR
33 # undef S_ISDIR
34 # undef S_ISDOOR
35 # undef S_ISFIFO
36 # undef S_ISLNK
37 # undef S_ISNAM
38 # undef S_ISMPB
39 # undef S_ISMPC
40 # undef S_ISNWK
41 # undef S_ISREG
42 # undef S_ISSOCK
43 #endif
44
45
46 #ifndef S_ISBLK
47 # ifdef S_IFBLK
48 #  define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
49 # else
50 #  define S_ISBLK(m) 0
51 # endif
52 #endif
53
54 #ifndef S_ISCHR
55 # ifdef S_IFCHR
56 #  define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
57 # else
58 #  define S_ISCHR(m) 0
59 # endif
60 #endif
61
62 #ifndef S_ISDIR
63 # ifdef S_IFDIR
64 #  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
65 # else
66 #  define S_ISDIR(m) 0
67 # endif
68 #endif
69
70 #ifndef S_ISDOOR /* Solaris 2.5 and up */
71 # ifdef S_IFDOOR
72 #  define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR)
73 # else
74 #  define S_ISDOOR(m) 0
75 # endif
76 #endif
77
78 #ifndef S_ISFIFO
79 # ifdef S_IFIFO
80 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
81 # else
82 #  define S_ISFIFO(m) 0
83 # endif
84 #endif
85
86 #ifndef S_ISLNK
87 # ifdef S_IFLNK
88 #  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
89 # else
90 #  define S_ISLNK(m) 0
91 # endif
92 #endif
93
94 #ifndef S_ISMPB /* V7 */
95 # ifdef S_IFMPB
96 #  define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
97 #  define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
98 # else
99 #  define S_ISMPB(m) 0
100 #  define S_ISMPC(m) 0
101 # endif
102 #endif
103
104 #ifndef S_ISNAM /* Xenix */
105 # ifdef S_IFNAM
106 #  define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
107 # else
108 #  define S_ISNAM(m) 0
109 # endif
110 #endif
111
112 #ifndef S_ISNWK /* HP/UX */
113 # ifdef S_IFNWK
114 #  define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
115 # else
116 #  define S_ISNWK(m) 0
117 # endif
118 #endif
119
120 #ifndef S_ISREG
121 # ifdef S_IFREG
122 #  define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
123 # else
124 #  define S_ISREG(m) 0
125 # endif
126 #endif
127
128 #ifndef S_ISSOCK
129 # ifdef S_IFSOCK
130 #  define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
131 # else
132 #  define S_ISSOCK(m) 0
133 # endif
134 #endif
135
136
137 #ifndef S_TYPEISSEM
138 # ifdef S_INSEM
139 #  define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
140 # else
141 #  define S_TYPEISSEM(p) 0
142 # endif
143 #endif
144
145 #ifndef S_TYPEISSHM
146 # ifdef S_INSHD
147 #  define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
148 # else
149 #  define S_TYPEISSHM(p) 0
150 # endif
151 #endif
152
153 #ifndef S_TYPEISMQ
154 # define S_TYPEISMQ(p) 0
155 #endif