1 /* Return a string describing the type of a file.
3 Copyright (C) 1993-1994, 2001-2002, 2004-2006, 2009-2011 Free Software
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* Written by Paul Eggert. */
23 #include "file-type.h"
26 #define _(text) gettext (text)
28 /* The attribute __pure__ was added in gcc 2.96. */
29 #undef _GL_ATTRIBUTE_PURE
30 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
31 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
33 # define _GL_ATTRIBUTE_PURE /* empty */
36 char const * _GL_ATTRIBUTE_PURE
37 file_type (struct stat const *st)
39 /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 for some of
42 To keep diagnostics grammatical in English, the returned string
43 must start with a consonant. */
45 if (S_ISREG (st->st_mode))
46 return st->st_size == 0 ? _("regular empty file") : _("regular file");
48 if (S_ISDIR (st->st_mode))
49 return _("directory");
51 if (S_ISBLK (st->st_mode))
52 return _("block special file");
54 if (S_ISCHR (st->st_mode))
55 return _("character special file");
57 if (S_ISFIFO (st->st_mode))
60 if (S_ISLNK (st->st_mode))
61 return _("symbolic link");
63 if (S_ISSOCK (st->st_mode))
67 return _("message queue");
70 return _("semaphore");
73 return _("shared memory object");
76 return _("typed memory object");
78 return _("weird file");