1 /* System dependent declarations.
3 Copyright (C) 1988-1989, 1992-1995, 1998, 2001-2002, 2004, 2006, 2009-2011
4 Free Software Foundation, Inc.
6 This file is part of GNU DIFF.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
25 # define IF_LINT(Code) Code
27 # define IF_LINT(Code) /* empty */
30 /* Define `__attribute__' and `volatile' first
31 so that they're used consistently in all system includes. */
32 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
33 # define __attribute__(x)
38 #include <sys/types.h>
41 #include "stat-macros.h"
43 #ifndef STAT_BLOCKSIZE
44 # if HAVE_STRUCT_STAT_ST_BLKSIZE
45 # define STAT_BLOCKSIZE(s) ((s).st_blksize)
47 # define STAT_BLOCKSIZE(s) (8 * 1024)
59 #ifndef _D_EXACT_NAMLEN
60 # define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)
64 #define EXIT_TROUBLE 2
72 #if ! HAVE_STRCASECOLL
73 # if HAVE_STRICOLL || defined stricoll
74 # define strcasecoll(a, b) stricoll (a, b)
76 # define strcasecoll(a, b) strcasecmp (a, b) /* best we can do */
79 #if ! (HAVE_STRCASECMP || defined strcasecmp)
80 int strcasecmp (char const *, char const *);
86 # define textdomain(Domainname) /* empty */
87 # undef bindtextdomain
88 # define bindtextdomain(Domainname, Dirname) /* empty */
91 #define _(msgid) gettext (msgid)
92 #define N_(msgid) msgid
96 /* ISDIGIT differs from isdigit, as follows:
97 - Its arg may be any int or unsigned int; it need not be an unsigned char.
98 - It's guaranteed to evaluate its argument exactly once.
99 - It's typically faster.
100 POSIX 1003.1-2001 says that only '0' through '9' are digits.
101 Prefer ISDIGIT to isdigit unless it's important to use the locale's
102 definition of `digit' even when the host does not conform to POSIX. */
103 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
108 #if !defined SIGCHLD && defined SIGCLD
109 # define SIGCHLD SIGCLD
114 #define MIN(a, b) ((a) <= (b) ? (a) : (b))
115 #define MAX(a, b) ((a) >= (b) ? (a) : (b))
118 #include <intprops.h>
119 #include "propername.h"
122 /* Type used for fast comparison of several bytes at a time. */
125 # define word uintmax_t
128 /* The integer type of a line number. Since files are read into main
129 memory, ptrdiff_t should be wide enough. */
131 typedef ptrdiff_t lin;
132 #define LIN_MAX PTRDIFF_MAX
133 verify (TYPE_SIGNED (lin));
134 verify (sizeof (ptrdiff_t) <= sizeof (lin));
135 verify (sizeof (lin) <= sizeof (long int));
137 /* This section contains POSIX-compliant defaults for macros
138 that are meant to be overridden by hand in config.h as needed. */
140 #ifndef file_name_cmp
141 # define file_name_cmp strcmp
144 #ifndef initialize_main
145 # define initialize_main(argcp, argvp)
149 # define NULL_DEVICE "/dev/null"
152 /* Do struct stat *S, *T describe the same special file? */
153 #ifndef same_special_file
154 # if HAVE_ST_RDEV && defined S_ISBLK && defined S_ISCHR
155 # define same_special_file(s, t) \
156 (((S_ISBLK ((s)->st_mode) && S_ISBLK ((t)->st_mode)) \
157 || (S_ISCHR ((s)->st_mode) && S_ISCHR ((t)->st_mode))) \
158 && (s)->st_rdev == (t)->st_rdev)
160 # define same_special_file(s, t) 0
164 /* Do struct stat *S, *T describe the same file? Answer -1 if unknown. */
166 # define same_file(s, t) \
167 ((((s)->st_ino == (t)->st_ino) && ((s)->st_dev == (t)->st_dev)) \
168 || same_special_file (s, t))
171 /* Do struct stat *S, *T have the same file attributes?
173 POSIX says that two files are identical if st_ino and st_dev are
174 the same, but many file systems incorrectly assign the same (device,
175 inode) pair to two distinct files, including:
177 - GNU/Linux NFS servers that export all local file systems as a
178 single NFS file system, if a local device number (st_dev) exceeds
179 255, or if a local inode number (st_ino) exceeds 16777215.
181 - Network Appliance NFS servers in snapshot directories; see
182 Network Appliance bug #195.
184 - ClearCase MVFS; see bug id ATRia04618.
186 Check whether two files that purport to be the same have the same
187 attributes, to work around instances of this common bug. Do not
188 inspect all attributes, only attributes useful in checking for this
191 It's possible for two distinct files on a buggy file system to have
192 the same attributes, but it's not worth slowing down all
193 implementations (or complicating the configuration) to cater to
194 these rare cases in buggy implementations. */
196 #ifndef same_file_attributes
197 # define same_file_attributes(s, t) \
198 ((s)->st_mode == (t)->st_mode \
199 && (s)->st_nlink == (t)->st_nlink \
200 && (s)->st_uid == (t)->st_uid \
201 && (s)->st_gid == (t)->st_gid \
202 && (s)->st_size == (t)->st_size \
203 && (s)->st_mtime == (t)->st_mtime \
204 && (s)->st_ctime == (t)->st_ctime)
207 #define STREQ(a, b) (strcmp (a, b) == 0)