Blame lib/file-type.c

Packit 33f14e
/* Return a string describing the type of a file.
Packit 33f14e
Packit 33f14e
   Copyright (C) 1993-1994, 2001-2002, 2004-2006, 2009-2017 Free Software
Packit 33f14e
   Foundation, Inc.
Packit 33f14e
Packit 33f14e
   This program is free software: you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3 of the License, or
Packit 33f14e
   (at your option) any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License
Packit 33f14e
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
/* Written by Paul Eggert.  */
Packit 33f14e
Packit 33f14e
#include <config.h>
Packit 33f14e
Packit 33f14e
#include "file-type.h"
Packit 33f14e
Packit 33f14e
#include <gettext.h>
Packit 33f14e
#define _(text) gettext (text)
Packit 33f14e
Packit 33f14e
char const *
Packit 33f14e
file_type (struct stat const *st)
Packit 33f14e
{
Packit 33f14e
  /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 for some of
Packit 33f14e
     these formats.
Packit 33f14e
Packit 33f14e
     To keep diagnostics grammatical in English, the returned string
Packit 33f14e
     must start with a consonant.  */
Packit 33f14e
Packit 33f14e
  /* Do these three first, as they're the most common.  */
Packit 33f14e
Packit 33f14e
  if (S_ISREG (st->st_mode))
Packit 33f14e
    return st->st_size == 0 ? _("regular empty file") : _("regular file");
Packit 33f14e
Packit 33f14e
  if (S_ISDIR (st->st_mode))
Packit 33f14e
    return _("directory");
Packit 33f14e
Packit 33f14e
  if (S_ISLNK (st->st_mode))
Packit 33f14e
    return _("symbolic link");
Packit 33f14e
Packit 33f14e
  /* Do the S_TYPEIS* macros next, as they may be implemented in terms
Packit 33f14e
     of S_ISNAM, and we want the more-specialized interpretation.  */
Packit 33f14e
Packit 33f14e
  if (S_TYPEISMQ (st))
Packit 33f14e
    return _("message queue");
Packit 33f14e
Packit 33f14e
  if (S_TYPEISSEM (st))
Packit 33f14e
    return _("semaphore");
Packit 33f14e
Packit 33f14e
  if (S_TYPEISSHM (st))
Packit 33f14e
    return _("shared memory object");
Packit 33f14e
Packit 33f14e
  if (S_TYPEISTMO (st))
Packit 33f14e
    return _("typed memory object");
Packit 33f14e
Packit 33f14e
  /* The remaining are in alphabetical order.  */
Packit 33f14e
Packit 33f14e
  if (S_ISBLK (st->st_mode))
Packit 33f14e
    return _("block special file");
Packit 33f14e
Packit 33f14e
  if (S_ISCHR (st->st_mode))
Packit 33f14e
    return _("character special file");
Packit 33f14e
Packit 33f14e
  if (S_ISCTG (st->st_mode))
Packit 33f14e
    return _("contiguous data");
Packit 33f14e
Packit 33f14e
  if (S_ISFIFO (st->st_mode))
Packit 33f14e
    return _("fifo");
Packit 33f14e
Packit 33f14e
  if (S_ISDOOR (st->st_mode))
Packit 33f14e
    return _("door");
Packit 33f14e
Packit 33f14e
  if (S_ISMPB (st->st_mode))
Packit 33f14e
    return _("multiplexed block special file");
Packit 33f14e
Packit 33f14e
  if (S_ISMPC (st->st_mode))
Packit 33f14e
    return _("multiplexed character special file");
Packit 33f14e
Packit 33f14e
  if (S_ISMPX (st->st_mode))
Packit 33f14e
    return _("multiplexed file");
Packit 33f14e
Packit 33f14e
  if (S_ISNAM (st->st_mode))
Packit 33f14e
    return _("named file");
Packit 33f14e
Packit 33f14e
  if (S_ISNWK (st->st_mode))
Packit 33f14e
    return _("network special file");
Packit 33f14e
Packit 33f14e
  if (S_ISOFD (st->st_mode))
Packit 33f14e
    return _("migrated file with data");
Packit 33f14e
Packit 33f14e
  if (S_ISOFL (st->st_mode))
Packit 33f14e
    return _("migrated file without data");
Packit 33f14e
Packit 33f14e
  if (S_ISPORT (st->st_mode))
Packit 33f14e
    return _("port");
Packit 33f14e
Packit 33f14e
  if (S_ISSOCK (st->st_mode))
Packit 33f14e
    return _("socket");
Packit 33f14e
Packit 33f14e
  if (S_ISWHT (st->st_mode))
Packit 33f14e
    return _("whiteout");
Packit 33f14e
Packit 33f14e
  return _("weird file");
Packit 33f14e
}