1170754Sdelphij/* Return a string describing the type of a file. 2170754Sdelphij 3170754Sdelphij Copyright (C) 1993, 1994, 2001, 2002, 2004 Free Software Foundation, Inc. 4170754Sdelphij 5170754Sdelphij This program is free software; you can redistribute it and/or modify 6170754Sdelphij it under the terms of the GNU General Public License as published by 7170754Sdelphij the Free Software Foundation; either version 2, or (at your option) 8170754Sdelphij any later version. 9170754Sdelphij 10170754Sdelphij This program is distributed in the hope that it will be useful, 11170754Sdelphij but WITHOUT ANY WARRANTY; without even the implied warranty of 12170754Sdelphij MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13170754Sdelphij GNU General Public License for more details. 14170754Sdelphij 15170754Sdelphij You should have received a copy of the GNU General Public License 16170754Sdelphij along with this program; if not, write to the Free Software Foundation, 17170754Sdelphij Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 18170754Sdelphij 19170754Sdelphij/* Written by Paul Eggert. */ 20170754Sdelphij 21170754Sdelphij#if HAVE_CONFIG_H 22170754Sdelphij# include <config.h> 23170754Sdelphij#endif 24170754Sdelphij 25170754Sdelphij#include <sys/types.h> 26170754Sdelphij#include <sys/stat.h> 27170754Sdelphij#include "file-type.h" 28170754Sdelphij 29170754Sdelphij#include <gettext.h> 30170754Sdelphij#define _(text) gettext (text) 31170754Sdelphij 32170754Sdelphijchar const * 33170754Sdelphijfile_type (struct stat const *st) 34170754Sdelphij{ 35170754Sdelphij /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 for some of 36170754Sdelphij these formats. 37170754Sdelphij 38170754Sdelphij To keep diagnostics grammatical in English, the returned string 39170754Sdelphij must start with a consonant. */ 40170754Sdelphij 41170754Sdelphij if (S_ISREG (st->st_mode)) 42170754Sdelphij return st->st_size == 0 ? _("regular empty file") : _("regular file"); 43170754Sdelphij 44170754Sdelphij if (S_ISDIR (st->st_mode)) 45170754Sdelphij return _("directory"); 46170754Sdelphij 47170754Sdelphij if (S_ISBLK (st->st_mode)) 48170754Sdelphij return _("block special file"); 49170754Sdelphij 50170754Sdelphij if (S_ISCHR (st->st_mode)) 51170754Sdelphij return _("character special file"); 52170754Sdelphij 53170754Sdelphij if (S_ISFIFO (st->st_mode)) 54170754Sdelphij return _("fifo"); 55170754Sdelphij 56170754Sdelphij if (S_ISLNK (st->st_mode)) 57170754Sdelphij return _("symbolic link"); 58170754Sdelphij 59170754Sdelphij if (S_ISSOCK (st->st_mode)) 60170754Sdelphij return _("socket"); 61170754Sdelphij 62170754Sdelphij if (S_TYPEISMQ (st)) 63170754Sdelphij return _("message queue"); 64170754Sdelphij 65170754Sdelphij if (S_TYPEISSEM (st)) 66170754Sdelphij return _("semaphore"); 67170754Sdelphij 68170754Sdelphij if (S_TYPEISSHM (st)) 69170754Sdelphij return _("shared memory object"); 70170754Sdelphij 71170754Sdelphij if (S_TYPEISTMO (st)) 72170754Sdelphij return _("typed memory object"); 73170754Sdelphij 74170754Sdelphij return _("weird file"); 75170754Sdelphij} 76