Blame src/system.h

Packit Service fdd496
/* System dependent declarations.
Packit Service fdd496
Packit Service fdd496
   Copyright (C) 1988-1989, 1992-1995, 1998, 2001-2002, 2004, 2006, 2009-2013,
Packit Service fdd496
   2015-2017 Free Software Foundation, Inc.
Packit Service fdd496
Packit Service fdd496
   This file is part of GNU DIFF.
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
#include <config.h>
Packit Service fdd496
Packit Service fdd496
/* Use this to suppress gcc's "...may be used before initialized" warnings. */
Packit Service fdd496
#ifdef lint
Packit Service fdd496
# define IF_LINT(Code) Code
Packit Service fdd496
#else
Packit Service fdd496
# define IF_LINT(Code) /* empty */
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
/* Define '__attribute__' and 'volatile' first
Packit Service fdd496
   so that they're used consistently in all system includes.  */
Packit Service fdd496
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
Packit Service fdd496
# define __attribute__(x)
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#include <verify.h>
Packit Service fdd496
Packit Service fdd496
#include <sys/types.h>
Packit Service fdd496
Packit Service fdd496
#include <sys/stat.h>
Packit Service fdd496
#include "stat-macros.h"
Packit Service fdd496
Packit Service fdd496
#ifndef STAT_BLOCKSIZE
Packit Service fdd496
# if HAVE_STRUCT_STAT_ST_BLKSIZE
Packit Service fdd496
#  define STAT_BLOCKSIZE(s) ((s).st_blksize)
Packit Service fdd496
# else
Packit Service fdd496
#  define STAT_BLOCKSIZE(s) (8 * 1024)
Packit Service fdd496
# endif
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#include <unistd.h>
Packit Service fdd496
Packit Service fdd496
#include <fcntl.h>
Packit Service fdd496
#include <time.h>
Packit Service fdd496
Packit Service fdd496
#include <sys/wait.h>
Packit Service fdd496
Packit Service fdd496
#include <dirent.h>
Packit Service fdd496
#ifndef _D_EXACT_NAMLEN
Packit Service fdd496
# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#include <stdlib.h>
Packit Service fdd496
#define EXIT_TROUBLE 2
Packit Service fdd496
Packit Service fdd496
#include <limits.h>
Packit Service fdd496
#include <locale.h>
Packit Service fdd496
#include <stddef.h>
Packit Service fdd496
#include <inttypes.h>
Packit Service fdd496
Packit Service fdd496
#include <string.h>
Packit Service fdd496
#if ! HAVE_STRCASECOLL
Packit Service fdd496
# if HAVE_STRICOLL || defined stricoll
Packit Service fdd496
#  define strcasecoll(a, b) stricoll (a, b)
Packit Service fdd496
# else
Packit Service fdd496
#  define strcasecoll(a, b) strcasecmp (a, b) /* best we can do */
Packit Service fdd496
# endif
Packit Service fdd496
#endif
Packit Service fdd496
#if ! (HAVE_STRCASECMP || defined strcasecmp)
Packit Service fdd496
int strcasecmp (char const *, char const *);
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#include <gettext.h>
Packit Service fdd496
#if ! ENABLE_NLS
Packit Service fdd496
# undef textdomain
Packit Service fdd496
# define textdomain(Domainname) /* empty */
Packit Service fdd496
# undef bindtextdomain
Packit Service fdd496
# define bindtextdomain(Domainname, Dirname) /* empty */
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#define _(msgid) gettext (msgid)
Packit Service fdd496
#define N_(msgid) msgid
Packit Service fdd496
Packit Service fdd496
#include <ctype.h>
Packit Service fdd496
Packit Service fdd496
/* ISDIGIT differs from isdigit, as follows:
Packit Service fdd496
   - Its arg may be any int or unsigned int; it need not be an unsigned char.
Packit Service fdd496
   - It's guaranteed to evaluate its argument exactly once.
Packit Service fdd496
   - It's typically faster.
Packit Service fdd496
   POSIX 1003.1-2001 says that only '0' through '9' are digits.
Packit Service fdd496
   Prefer ISDIGIT to isdigit unless it's important to use the locale's
Packit Service fdd496
   definition of 'digit' even when the host does not conform to POSIX.  */
Packit Service fdd496
#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
Packit Service fdd496
Packit Service fdd496
#include <errno.h>
Packit Service fdd496
Packit Service fdd496
#include <signal.h>
Packit Service fdd496
#if !defined SIGCHLD && defined SIGCLD
Packit Service fdd496
# define SIGCHLD SIGCLD
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#undef MIN
Packit Service fdd496
#undef MAX
Packit Service fdd496
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
Packit Service fdd496
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
Packit Service fdd496
Packit Service fdd496
#include <stdbool.h>
Packit Service fdd496
#include <intprops.h>
Packit Service fdd496
#include "propername.h"
Packit Service fdd496
#include "version.h"
Packit Service fdd496
Packit Service fdd496
/* Type used for fast comparison of several bytes at a time.
Packit Service fdd496
   This used to be uintmax_t, but changing it to size_t
Packit Service fdd496
   made plain 'cmp' 90% faster (GCC 4.8.1, x86).  */
Packit Service fdd496
Packit Service fdd496
#ifndef word
Packit Service fdd496
# define word size_t
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
/* The signed integer type of a line number.  Since files are read
Packit Service fdd496
   into main memory, ptrdiff_t should be wide enough.  */
Packit Service fdd496
Packit Service fdd496
typedef ptrdiff_t lin;
Packit Service fdd496
#define LIN_MAX PTRDIFF_MAX
Packit Service fdd496
Packit Service fdd496
/* The signed integer type for printing line numbers, and its printf
Packit Service fdd496
   length modifier.  This is not simply ptrdiff_t, to cater to older
Packit Service fdd496
   and/or nonstandard C libraries where "l" works but "ll" and "t" do
Packit Service fdd496
   not, or where 'long' is too narrow and "ll" works but "t" does not.  */
Packit Service fdd496
Packit Service fdd496
#if LIN_MAX <= LONG_MAX
Packit Service fdd496
typedef long int printint;
Packit Service fdd496
# define pI "l"
Packit Service fdd496
#elif LIN_MAX <= LLONG_MAX
Packit Service fdd496
typedef long long int printint;
Packit Service fdd496
# define pI "ll"
Packit Service fdd496
#else
Packit Service fdd496
typedef ptrdiff_t printint;
Packit Service fdd496
# define pI "t"
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
verify (TYPE_SIGNED (lin));
Packit Service fdd496
verify (TYPE_SIGNED (printint));
Packit Service fdd496
verify (LIN_MAX == TYPE_MAXIMUM (lin));
Packit Service fdd496
verify (LIN_MAX <= TYPE_MAXIMUM (printint));
Packit Service fdd496
Packit Service fdd496
/* Limit so that 2 * CONTEXT + 1 does not overflow.  */
Packit Service fdd496
Packit Service fdd496
#define CONTEXT_MAX ((LIN_MAX - 1) / 2)
Packit Service fdd496
Packit Service fdd496

Packit Service fdd496
/* This section contains POSIX-compliant defaults for macros
Packit Service fdd496
   that are meant to be overridden by hand in config.h as needed.  */
Packit Service fdd496
Packit Service fdd496
#ifndef file_name_cmp
Packit Service fdd496
# define file_name_cmp strcmp
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#ifndef initialize_main
Packit Service fdd496
# define initialize_main(argcp, argvp)
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#ifndef NULL_DEVICE
Packit Service fdd496
# define NULL_DEVICE "/dev/null"
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
/* Do struct stat *S, *T describe the same special file?  */
Packit Service fdd496
#ifndef same_special_file
Packit Service fdd496
# if HAVE_STRUCT_STAT_ST_RDEV && defined S_ISBLK && defined S_ISCHR
Packit Service fdd496
#  define same_special_file(s, t) \
Packit Service fdd496
     (((S_ISBLK ((s)->st_mode) && S_ISBLK ((t)->st_mode)) \
Packit Service fdd496
       || (S_ISCHR ((s)->st_mode) && S_ISCHR ((t)->st_mode))) \
Packit Service fdd496
      && (s)->st_rdev == (t)->st_rdev)
Packit Service fdd496
# else
Packit Service fdd496
#  define same_special_file(s, t) 0
Packit Service fdd496
# endif
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
/* Do struct stat *S, *T describe the same file?  Answer -1 if unknown.  */
Packit Service fdd496
#ifndef same_file
Packit Service fdd496
# define same_file(s, t) \
Packit Service fdd496
    ((((s)->st_ino == (t)->st_ino) && ((s)->st_dev == (t)->st_dev)) \
Packit Service fdd496
     || same_special_file (s, t))
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
/* Do struct stat *S, *T have the same file attributes?
Packit Service fdd496
Packit Service fdd496
   POSIX says that two files are identical if st_ino and st_dev are
Packit Service fdd496
   the same, but many file systems incorrectly assign the same (device,
Packit Service fdd496
   inode) pair to two distinct files, including:
Packit Service fdd496
Packit Service fdd496
   - GNU/Linux NFS servers that export all local file systems as a
Packit Service fdd496
     single NFS file system, if a local device number (st_dev) exceeds
Packit Service fdd496
     255, or if a local inode number (st_ino) exceeds 16777215.
Packit Service fdd496
Packit Service fdd496
   - Network Appliance NFS servers in snapshot directories; see
Packit Service fdd496
     Network Appliance bug #195.
Packit Service fdd496
Packit Service fdd496
   - ClearCase MVFS; see bug id ATRia04618.
Packit Service fdd496
Packit Service fdd496
   Check whether two files that purport to be the same have the same
Packit Service fdd496
   attributes, to work around instances of this common bug.  Do not
Packit Service fdd496
   inspect all attributes, only attributes useful in checking for this
Packit Service fdd496
   bug.
Packit Service fdd496
Packit Service fdd496
   It's possible for two distinct files on a buggy file system to have
Packit Service fdd496
   the same attributes, but it's not worth slowing down all
Packit Service fdd496
   implementations (or complicating the configuration) to cater to
Packit Service fdd496
   these rare cases in buggy implementations.  */
Packit Service fdd496
Packit Service fdd496
#ifndef same_file_attributes
Packit Service fdd496
# define same_file_attributes(s, t) \
Packit Service fdd496
   ((s)->st_mode == (t)->st_mode \
Packit Service fdd496
    && (s)->st_nlink == (t)->st_nlink \
Packit Service fdd496
    && (s)->st_uid == (t)->st_uid \
Packit Service fdd496
    && (s)->st_gid == (t)->st_gid \
Packit Service fdd496
    && (s)->st_size == (t)->st_size \
Packit Service fdd496
    && (s)->st_mtime == (t)->st_mtime \
Packit Service fdd496
    && (s)->st_ctime == (t)->st_ctime)
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#define STREQ(a, b) (strcmp (a, b) == 0)
Packit Service fdd496
Packit Service fdd496
#ifndef FALLTHROUGH
Packit Service fdd496
# if __GNUC__ < 7
Packit Service fdd496
#  define FALLTHROUGH ((void) 0)
Packit Service fdd496
# else
Packit Service fdd496
#  define FALLTHROUGH __attribute__ ((__fallthrough__))
Packit Service fdd496
# endif
Packit Service fdd496
#endif