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