1 /* Return a string describing the type of a file.
3 Copyright (C) 1993, 1994, 2001, 2002, 2004, 2005, 2006 Free
4 Software Foundation, Inc.
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 2, or (at your option)
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, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 /* Written by Paul Eggert. */
24 #include "file-type.h"
26 #include "stat-macros.h"
29 #define _(text) gettext (text)
32 file_type (struct stat const *st)
34 /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 for some of
37 To keep diagnostics grammatical in English, the returned string
38 must start with a consonant. */
40 if (S_ISREG (st->st_mode))
41 return st->st_size == 0 ? _("regular empty file") : _("regular file");
43 if (S_ISDIR (st->st_mode))
44 return _("directory");
46 if (S_ISBLK (st->st_mode))
47 return _("block special file");
49 if (S_ISCHR (st->st_mode))
50 return _("character special file");
52 if (S_ISFIFO (st->st_mode))
55 if (S_ISLNK (st->st_mode))
56 return _("symbolic link");
58 if (S_ISSOCK (st->st_mode))
62 return _("message queue");
65 return _("semaphore");
68 return _("shared memory object");
71 return _("typed memory object");
73 return _("weird file");