Update from GNU gettext 0.15.
[gnulib.git] / lib / file-type.c
1 /* Return a string describing the type of a file.
2
3    Copyright (C) 1993, 1994, 2001, 2002, 2004, 2005 Free Software
4    Foundation, Inc.
5
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)
9    any later version.
10
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.
15
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.  */
19
20 /* Written by Paul Eggert.  */
21
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25
26 #include "file-type.h"
27
28 #include "stat-macros.h"
29
30 #include <gettext.h>
31 #define _(text) gettext (text)
32
33 char const *
34 file_type (struct stat const *st)
35 {
36   /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 for some of
37      these formats.
38
39      To keep diagnostics grammatical in English, the returned string
40      must start with a consonant.  */
41
42   if (S_ISREG (st->st_mode))
43     return st->st_size == 0 ? _("regular empty file") : _("regular file");
44
45   if (S_ISDIR (st->st_mode))
46     return _("directory");
47
48   if (S_ISBLK (st->st_mode))
49     return _("block special file");
50
51   if (S_ISCHR (st->st_mode))
52     return _("character special file");
53
54   if (S_ISFIFO (st->st_mode))
55     return _("fifo");
56
57   if (S_ISLNK (st->st_mode))
58     return _("symbolic link");
59
60   if (S_ISSOCK (st->st_mode))
61     return _("socket");
62
63   if (S_TYPEISMQ (st))
64     return _("message queue");
65
66   if (S_TYPEISSEM (st))
67     return _("semaphore");
68
69   if (S_TYPEISSHM (st))
70     return _("shared memory object");
71
72   if (S_TYPEISTMO (st))
73     return _("typed memory object");
74
75   return _("weird file");
76 }