remove typo
[gnulib.git] / lib / file-type.c
1 /* return a string describing the type of a file
2    Copyright (C) 2002 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17
18 /* Extracted from diffutils/src/diff.c.  */
19
20 #include "file-type.h"
21
22 #if ENABLE_NLS
23 # include <libintl.h>
24 # define _(text) gettext (text)
25 #else
26 # define _(text) text
27 #endif
28
29 char const *
30 file_type (struct stat const *st)
31 {
32   /* See POSIX 1003.1-2001 for these formats.
33
34      To keep diagnostics grammatical in English, the returned string
35      must start with a consonant.  */
36
37   if (S_ISREG (st->st_mode))
38     return st->st_size == 0 ? _("regular empty file") : _("regular file");
39
40   if (S_ISDIR (st->st_mode))
41     return _("directory");
42
43   if (S_ISBLK (st->st_mode))
44     return _("block special file");
45
46   if (S_ISCHR (st->st_mode))
47     return _("character special file");
48
49   if (S_ISFIFO (st->st_mode))
50     return _("fifo");
51
52   if (S_ISLNK (st->st_mode))
53     return _("symbolic link");
54
55   if (S_ISSOCK (st->st_mode))
56     return _("socket");
57
58   if (S_TYPEISMQ (st))
59     return _("message queue");
60
61   if (S_TYPEISSEM (st))
62     return _("semaphore");
63
64   if (S_TYPEISSHM (st))
65     return _("shared memory object");
66
67   return _("weird file");
68 }