Blame lib/file-type.c

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