| 1 |
/* System dependent declarations. |
| 2 |
|
| 3 |
Copyright (C) 1988-1989, 1992-1995, 1998, 2001-2002, 2004, 2006, 2009-2013, |
| 4 |
2015-2025 Free Software Foundation, Inc. |
| 5 |
|
| 6 |
This file is part of GNU DIFF. |
| 7 |
|
| 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. |
| 12 |
|
| 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. |
| 17 |
|
| 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/>. */ |
| 20 |
|
| 21 |
#include <config.h> |
| 22 |
|
| 23 |
#include <verify.h> |
| 24 |
|
| 25 |
#include <sys/types.h> |
| 26 |
|
| 27 |
#include <sys/stat.h> |
| 28 |
#include <stat-macros.h> |
| 29 |
#include <stat-size.h> |
| 30 |
#include <stat-time.h> |
| 31 |
#include <timespec.h> |
| 32 |
|
| 33 |
#include <unistd.h> |
| 34 |
|
| 35 |
#include <fcntl.h> |
| 36 |
#include <time.h> |
| 37 |
|
| 38 |
#include <sys/wait.h> |
| 39 |
|
| 40 |
#include <dirent.h> |
| 41 |
#ifndef _D_EXACT_NAMLEN |
| 42 |
# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name) |
| 43 |
#endif |
| 44 |
|
| 45 |
#include <stdlib.h> |
| 46 |
|
| 47 |
#include <inttypes.h> |
| 48 |
#include <limits.h> |
| 49 |
#include <locale.h> |
| 50 |
#include <stdbit.h> |
| 51 |
#include <stdckdint.h> |
| 52 |
#include <stddef.h> |
| 53 |
#include <string.h> |
| 54 |
|
| 55 |
#include <gettext.h> |
| 56 |
#if ! ENABLE_NLS |
| 57 |
# undef textdomain |
| 58 |
# define textdomain(Domainname) /* empty */ |
| 59 |
# undef bindtextdomain |
| 60 |
# define bindtextdomain(Domainname, Dirname) /* empty */ |
| 61 |
#endif |
| 62 |
|
| 63 |
#define _(msgid) gettext (msgid) |
| 64 |
#define N_(msgid) msgid |
| 65 |
|
| 66 |
#include <errno.h> |
| 67 |
|
| 68 |
#include <signal.h> |
| 69 |
#if !defined SIGCHLD && defined SIGCLD |
| 70 |
# define SIGCHLD SIGCLD |
| 71 |
#endif |
| 72 |
|
| 73 |
#include <attribute.h> |
| 74 |
#include <idx.h> |
| 75 |
#include <intprops.h> |
| 76 |
#include <minmax.h> |
| 77 |
#include <propername.h> |
| 78 |
#include <same-inode.h> |
| 79 |
|
| 80 |
#include "version.h" |
| 81 |
|
| 82 |
/* Evaluate an assertion E that is guaranteed to be true. |
| 83 |
E should not crash, loop forever, or have side effects. */ |
| 84 |
#if defined DDEBUG && !defined NDEBUG |
| 85 |
/* Abort the program if E is false. */ |
| 86 |
# include <assert.h> |
| 87 |
# define dassert(e) assert (e) |
| 88 |
#else |
| 89 |
/* The compiler can assume E, as behavior is undefined otherwise. */ |
| 90 |
# define dassert(e) assume (e) |
| 91 |
#endif |
| 92 |
|
| 93 |
#ifndef SYSTEM_INLINE |
| 94 |
# define SYSTEM_INLINE _GL_INLINE |
| 95 |
#endif |
| 96 |
|
| 97 |
_GL_INLINE_HEADER_BEGIN |
| 98 |
|
| 99 |
/* Type used for fast comparison of several bytes at a time. |
| 100 |
The type is a pointer to an incomplete struct, |
| 101 |
so that its values are less likely to be misused. |
| 102 |
This used to be uintmax_t, but changing it to the size of a pointer |
| 103 |
made plain 'cmp' 90% faster (GCC 4.8.1, x86). */ |
| 104 |
|
| 105 |
#ifndef word |
| 106 |
typedef struct incomplete *word; |
| 107 |
#endif |
| 108 |
|
| 109 |
/* The signed integer type of a line number. Since files are read |
| 110 |
into main memory, ptrdiff_t should be wide enough. pI is for |
| 111 |
printing line numbers. */ |
| 112 |
|
| 113 |
typedef ptrdiff_t lin; |
| 114 |
#define LIN_MAX PTRDIFF_MAX |
| 115 |
#define pI "t" |
| 116 |
static_assert (LIN_MAX == IDX_MAX); |
| 117 |
|
| 118 |
/* This section contains POSIX-compliant defaults for macros |
| 119 |
that are meant to be overridden by hand in config.h as needed. */ |
| 120 |
|
| 121 |
#ifndef file_name_cmp |
| 122 |
# define file_name_cmp strcmp |
| 123 |
#endif |
| 124 |
|
| 125 |
#ifndef initialize_main |
| 126 |
# define initialize_main(argcp, argvp) |
| 127 |
#endif |
| 128 |
|
| 129 |
#ifndef NULL_DEVICE |
| 130 |
# define NULL_DEVICE "/dev/null" |
| 131 |
#endif |
| 132 |
|
| 133 |
#define STREQ(a, b) (strcmp (a, b) == 0) |
| 134 |
|
| 135 |
/* Return the floor of the log base 2 of N. Return -1 if N is zero. */ |
| 136 |
SYSTEM_INLINE int floor_log2 (idx_t n) |
| 137 |
{ |
| 138 |
static_assert (IDX_MAX <= SIZE_MAX); |
| 139 |
size_t s = n; |
| 140 |
int w = stdc_bit_width (s); |
| 141 |
return w - 1; |
| 142 |
} |
| 143 |
|
| 144 |
_GL_INLINE_HEADER_END |
| 145 |
|
| 146 |
extern bool same_file (struct stat const *, struct stat const *) |
| 147 |
ATTRIBUTE_PURE; |
| 148 |
extern off_t stat_size (struct stat const *) |
| 149 |
ATTRIBUTE_PURE; |