xref: /freebsd-src/contrib/diff/lib/file-type.c (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.  */
20*18fd37a7SXin LI 
21*18fd37a7SXin LI #if HAVE_CONFIG_H
22*18fd37a7SXin LI # include <config.h>
23*18fd37a7SXin LI #endif
24*18fd37a7SXin LI 
25*18fd37a7SXin LI #include <sys/types.h>
26*18fd37a7SXin LI #include <sys/stat.h>
27*18fd37a7SXin LI #include "file-type.h"
28*18fd37a7SXin LI 
29*18fd37a7SXin LI #include <gettext.h>
30*18fd37a7SXin LI #define _(text) gettext (text)
31*18fd37a7SXin LI 
32*18fd37a7SXin LI char const *
file_type(struct stat const * st)33*18fd37a7SXin LI file_type (struct stat const *st)
34*18fd37a7SXin LI {
35*18fd37a7SXin LI   /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 for some of
36*18fd37a7SXin LI      these formats.
37*18fd37a7SXin LI 
38*18fd37a7SXin LI      To keep diagnostics grammatical in English, the returned string
39*18fd37a7SXin LI      must start with a consonant.  */
40*18fd37a7SXin LI 
41*18fd37a7SXin LI   if (S_ISREG (st->st_mode))
42*18fd37a7SXin LI     return st->st_size == 0 ? _("regular empty file") : _("regular file");
43*18fd37a7SXin LI 
44*18fd37a7SXin LI   if (S_ISDIR (st->st_mode))
45*18fd37a7SXin LI     return _("directory");
46*18fd37a7SXin LI 
47*18fd37a7SXin LI   if (S_ISBLK (st->st_mode))
48*18fd37a7SXin LI     return _("block special file");
49*18fd37a7SXin LI 
50*18fd37a7SXin LI   if (S_ISCHR (st->st_mode))
51*18fd37a7SXin LI     return _("character special file");
52*18fd37a7SXin LI 
53*18fd37a7SXin LI   if (S_ISFIFO (st->st_mode))
54*18fd37a7SXin LI     return _("fifo");
55*18fd37a7SXin LI 
56*18fd37a7SXin LI   if (S_ISLNK (st->st_mode))
57*18fd37a7SXin LI     return _("symbolic link");
58*18fd37a7SXin LI 
59*18fd37a7SXin LI   if (S_ISSOCK (st->st_mode))
60*18fd37a7SXin LI     return _("socket");
61*18fd37a7SXin LI 
62*18fd37a7SXin LI   if (S_TYPEISMQ (st))
63*18fd37a7SXin LI     return _("message queue");
64*18fd37a7SXin LI 
65*18fd37a7SXin LI   if (S_TYPEISSEM (st))
66*18fd37a7SXin LI     return _("semaphore");
67*18fd37a7SXin LI 
68*18fd37a7SXin LI   if (S_TYPEISSHM (st))
69*18fd37a7SXin LI     return _("shared memory object");
70*18fd37a7SXin LI 
71*18fd37a7SXin LI   if (S_TYPEISTMO (st))
72*18fd37a7SXin LI     return _("typed memory object");
73*18fd37a7SXin LI 
74*18fd37a7SXin LI   return _("weird file");
75*18fd37a7SXin LI }
76