maint: post-release administrivia
[diffutils.git] / src / system.h
blob19a087d4468650b5aa55d421ae692ada00062448
1 /* System dependent declarations.
3 Copyright (C) 1988-1989, 1992-1995, 1998, 2001-2002, 2004, 2006, 2009-2013,
4 2015-2025 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/>. */
21 #include <config.h>
23 #include <verify.h>
25 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stat-macros.h>
29 #include <stat-size.h>
30 #include <stat-time.h>
31 #include <timespec.h>
33 #include <unistd.h>
35 #include <fcntl.h>
36 #include <time.h>
38 #include <sys/wait.h>
40 #include <dirent.h>
41 #ifndef _D_EXACT_NAMLEN
42 # define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)
43 #endif
45 #include <stdlib.h>
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>
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
63 #define _(msgid) gettext (msgid)
64 #define N_(msgid) msgid
66 #include <errno.h>
68 #include <signal.h>
69 #if !defined SIGCHLD && defined SIGCLD
70 # define SIGCHLD SIGCLD
71 #endif
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>
80 #include "version.h"
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
93 #ifndef SYSTEM_INLINE
94 # define SYSTEM_INLINE _GL_INLINE
95 #endif
97 _GL_INLINE_HEADER_BEGIN
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). */
105 #ifndef word
106 typedef struct incomplete *word;
107 #endif
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. */
113 typedef ptrdiff_t lin;
114 #define LIN_MAX PTRDIFF_MAX
115 #define pI "t"
116 static_assert (LIN_MAX == IDX_MAX);
118 /* This section contains POSIX-compliant defaults for macros
119 that are meant to be overridden by hand in config.h as needed. */
121 #ifndef file_name_cmp
122 # define file_name_cmp strcmp
123 #endif
125 #ifndef initialize_main
126 # define initialize_main(argcp, argvp)
127 #endif
129 #ifndef NULL_DEVICE
130 # define NULL_DEVICE "/dev/null"
131 #endif
133 #define STREQ(a, b) (strcmp (a, b) == 0)
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)
138 static_assert (IDX_MAX <= SIZE_MAX);
139 size_t s = n;
140 int w = stdc_bit_width (s);
141 return w - 1;
144 _GL_INLINE_HEADER_END
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;