188794Sjake/* Return a string describing the type of a file.
288794Sjake
388794Sjake   Copyright (C) 1993, 1994, 2001, 2002, 2004 Free Software Foundation, Inc.
488794Sjake
588794Sjake   This program is free software; you can redistribute it and/or modify
688794Sjake   it under the terms of the GNU General Public License as published by
788794Sjake   the Free Software Foundation; either version 2, or (at your option)
888794Sjake   any later version.
988794Sjake
1088794Sjake   This program is distributed in the hope that it will be useful,
1188794Sjake   but WITHOUT ANY WARRANTY; without even the implied warranty of
1288794Sjake   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1388794Sjake   GNU General Public License for more details.
1488794Sjake
1588794Sjake   You should have received a copy of the GNU General Public License
1688794Sjake   along with this program; if not, write to the Free Software Foundation,
1788794Sjake   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
1888794Sjake
1988794Sjake/* Written by Paul Eggert.  */
2088794Sjake
2188794Sjake#if HAVE_CONFIG_H
2288794Sjake# include <config.h>
2388794Sjake#endif
2488794Sjake
2588794Sjake#include <sys/types.h>
2688794Sjake#include <sys/stat.h>
2788794Sjake#include "file-type.h"
2888794Sjake
2988794Sjake#include <gettext.h>
3088794Sjake#define _(text) gettext (text)
3188794Sjake
3288794Sjakechar const *
3388794Sjakefile_type (struct stat const *st)
3488794Sjake{
3595587Sjake  /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 for some of
3695587Sjake     these formats.
3788794Sjake
3888794Sjake     To keep diagnostics grammatical in English, the returned string
39124182Snectar     must start with a consonant.  */
4095587Sjake
4188794Sjake  if (S_ISREG (st->st_mode))
42124182Snectar    return st->st_size == 0 ? _("regular empty file") : _("regular file");
4388794Sjake
4488794Sjake  if (S_ISDIR (st->st_mode))
45124722Snectar    return _("directory");
46124722Snectar
47124722Snectar  if (S_ISBLK (st->st_mode))
48124722Snectar    return _("block special file");
4988794Sjake
5088794Sjake  if (S_ISCHR (st->st_mode))
5188794Sjake    return _("character special file");
5288794Sjake
5388794Sjake  if (S_ISFIFO (st->st_mode))
5488794Sjake    return _("fifo");
5588794Sjake
5688794Sjake  if (S_ISLNK (st->st_mode))
5788794Sjake    return _("symbolic link");
5888794Sjake
5988794Sjake  if (S_ISSOCK (st->st_mode))
6088794Sjake    return _("socket");
6188794Sjake
6288794Sjake  if (S_TYPEISMQ (st))
6388794Sjake    return _("message queue");
6488794Sjake
6588794Sjake  if (S_TYPEISSEM (st))
6688794Sjake    return _("semaphore");
6788794Sjake
6888794Sjake  if (S_TYPEISSHM (st))
6988794Sjake    return _("shared memory object");
7088794Sjake
7188794Sjake  if (S_TYPEISTMO (st))
7288794Sjake    return _("typed memory object");
7388794Sjake
7488794Sjake  return _("weird file");
7588794Sjake}
7688794Sjake