file-type.c revision 170755
150477Speter/* Return a string describing the type of a file.
25540Sugen
3156813Sru   Copyright (C) 1993, 1994, 2001, 2002, 2004 Free Software Foundation, Inc.
4156813Sru
5193532Sluigi   This program is free software; you can redistribute it and/or modify
670711Sobrien   it under the terms of the GNU General Public License as published by
740440Speter   the Free Software Foundation; either version 2, or (at your option)
8134346Sru   any later version.
9220124Sae
10200636Sluigi   This program is distributed in the hope that it will be useful,
11227085Sbz   but WITHOUT ANY WARRANTY; without even the implied warranty of
1270711Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1345872Speter   GNU General Public License for more details.
14171173Smlaier
155540Sugen   You should have received a copy of the GNU General Public License
165544Sugen   along with this program; if not, write to the Free Software Foundation,
175540Sugen   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
1816619Sbde
195540Sugen/* Written by Paul Eggert.  */
2029272Speter
2129272Speter#if HAVE_CONFIG_H
2229272Speter# include <config.h>
235540Sugen#endif
24152928Sume
25225793Sbz#include <sys/types.h>
26225793Sbz#include <sys/stat.h>
27225793Sbz#include "file-type.h"
28225793Sbz
29156813Sru#include <gettext.h>
30152928Sume#define _(text) gettext (text)
31152928Sume
32152928Sumechar const *
33152928Sumefile_type (struct stat const *st)
34152928Sume{
3560966Speter  /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 for some of
36     these formats.
37
38     To keep diagnostics grammatical in English, the returned string
39     must start with a consonant.  */
40
41  if (S_ISREG (st->st_mode))
42    return st->st_size == 0 ? _("regular empty file") : _("regular file");
43
44  if (S_ISDIR (st->st_mode))
45    return _("directory");
46
47  if (S_ISBLK (st->st_mode))
48    return _("block special file");
49
50  if (S_ISCHR (st->st_mode))
51    return _("character special file");
52
53  if (S_ISFIFO (st->st_mode))
54    return _("fifo");
55
56  if (S_ISLNK (st->st_mode))
57    return _("symbolic link");
58
59  if (S_ISSOCK (st->st_mode))
60    return _("socket");
61
62  if (S_TYPEISMQ (st))
63    return _("message queue");
64
65  if (S_TYPEISSEM (st))
66    return _("semaphore");
67
68  if (S_TYPEISSHM (st))
69    return _("shared memory object");
70
71  if (S_TYPEISTMO (st))
72    return _("typed memory object");
73
74  return _("weird file");
75}
76