maint: update bootstrap from gnulib
[cppi.git] / src / system.h
blob29d0a99fc46bd767ad0c7942daad7666144393ff
1 /* system-dependent definitions; derived from those of coreutils
2 Copyright (C) 1989, 1991-2008, 2010-2021, 2023-2024 Free Software
3 Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Include sys/types.h before this file. */
20 #if 2 <= __GLIBC__ && 2 <= __GLIBC_MINOR__
21 # if ! defined _SYS_TYPES_H
22 # error "you must include <sys/types.h> before including this file"
23 # endif
24 #endif
26 #include <sys/stat.h>
28 #if HAVE_SYS_PARAM_H
29 # include <sys/param.h>
30 #endif
32 #include <unistd.h>
33 #include <limits.h>
34 #include <time.h>
35 #include <string.h>
36 #include <errno.h>
37 #include "configmake.h"
39 #include <stdbool.h>
40 #include <stdlib.h>
42 /* Exit statuses for programs like 'env' that exec other programs.
43 EXIT_FAILURE might not be 1, so use EXIT_FAIL in such programs. */
44 enum
46 EXIT_FAIL = 1,
47 EXIT_CANNOT_INVOKE = 126,
48 EXIT_ENOENT = 127
51 #include "exitfail.h"
53 /* Redirection and wildcarding when done by the utility itself.
54 Generally a noop, but used in particular for native VMS. */
55 #ifndef initialize_main
56 # define initialize_main(ac, av)
57 #endif
59 #include "stat-macros.h"
60 #include <inttypes.h>
61 #include <ctype.h>
63 #if ! (defined isblank || HAVE_DECL_ISBLANK)
64 # define isblank(c) ((c) == ' ' || (c) == '\t')
65 #endif
67 /* ISDIGIT differs from isdigit, as follows:
68 - Its arg may be any int or unsigned int; it need not be an unsigned char
69 or EOF.
70 - It's typically faster.
71 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
72 isdigit unless it's important to use the locale's definition
73 of `digit' even when the host does not conform to POSIX. */
74 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
76 /* Convert a possibly-signed character to an unsigned character. This is
77 a bit safer than casting to unsigned char, since it catches some type
78 errors that the cast doesn't. */
79 static inline unsigned char to_uchar (char ch) { return ch; }
81 #include <locale.h>
83 /* Take care of NLS matters. */
85 #include "gettext.h"
86 #if ! ENABLE_NLS
87 # undef textdomain
88 # define textdomain(Domainname) /* empty */
89 # undef bindtextdomain
90 # define bindtextdomain(Domainname, Dirname) /* empty */
91 #endif
93 #define _(msgid) gettext (msgid)
94 #define N_(msgid) msgid
96 #define STREQ(a, b) (strcmp ((a), (b)) == 0)
98 #include "xalloc.h"
99 #include "verify.h"
101 #include "unlocked-io.h"
103 /* Factor out some of the common --help and --version processing code. */
105 /* These enum values cannot possibly conflict with the option values
106 ordinarily used by commands, including CHAR_MAX + 1, etc. Avoid
107 CHAR_MIN - 1, as it may equal -1, the getopt end-of-options value. */
108 enum
110 GETOPT_HELP_CHAR = (CHAR_MIN - 2),
111 GETOPT_VERSION_CHAR = (CHAR_MIN - 3)
114 #define GETOPT_HELP_OPTION_DECL \
115 "help", no_argument, NULL, GETOPT_HELP_CHAR
116 #define GETOPT_VERSION_OPTION_DECL \
117 "version", no_argument, NULL, GETOPT_VERSION_CHAR
119 #define case_GETOPT_HELP_CHAR \
120 case GETOPT_HELP_CHAR: \
121 usage (EXIT_SUCCESS); \
122 break;
124 /* Program_name must be a literal string.
125 Usually it is just PROGRAM_NAME. */
126 #define USAGE_BUILTIN_WARNING \
127 _("\n" \
128 "NOTE: your shell may have its own version of %s, which usually supersedes\n" \
129 "the version described here. Please refer to your shell's documentation\n" \
130 "for details about the options it supports.\n")
132 #define HELP_OPTION_DESCRIPTION \
133 _(" --help display this help and exit\n")
134 #define VERSION_OPTION_DESCRIPTION \
135 _(" --version output version information and exit\n")
137 #include "closeout.h"
138 #include "version-etc.h"
140 #define case_GETOPT_VERSION_CHAR(Program_name, Authors) \
141 case GETOPT_VERSION_CHAR: \
142 version_etc (stdout, Program_name, PACKAGE_NAME, VERSION, Authors, \
143 (char *) NULL); \
144 exit (EXIT_SUCCESS); \
145 break;
147 #ifndef MAX
148 # define MAX(a, b) ((a) > (b) ? (a) : (b))
149 #endif
151 #ifndef MIN
152 # define MIN(a,b) (((a) < (b)) ? (a) : (b))
153 #endif
155 #include "progname.h"
156 #include "intprops.h"
158 #ifndef SSIZE_MAX
159 # define SSIZE_MAX TYPE_MAXIMUM (ssize_t)
160 #endif
162 #ifndef OFF_T_MIN
163 # define OFF_T_MIN TYPE_MINIMUM (off_t)
164 #endif
166 #ifndef OFF_T_MAX
167 # define OFF_T_MAX TYPE_MAXIMUM (off_t)
168 #endif
170 #ifndef UID_T_MAX
171 # define UID_T_MAX TYPE_MAXIMUM (uid_t)
172 #endif
174 #ifndef GID_T_MAX
175 # define GID_T_MAX TYPE_MAXIMUM (gid_t)
176 #endif
178 #ifndef PID_T_MAX
179 # define PID_T_MAX TYPE_MAXIMUM (pid_t)
180 #endif
182 /* Use this to suppress gcc's `...may be used before initialized' warnings. */
183 #ifdef lint
184 # define IF_LINT(Code) Code
185 #else
186 # define IF_LINT(Code) /* empty */
187 #endif
189 #ifndef __attribute__
190 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
191 # define __attribute__(x) /* empty */
192 # endif
193 #endif
195 #ifndef ATTRIBUTE_NORETURN
196 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
197 #endif
199 #ifndef ATTRIBUTE_UNUSED
200 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
201 #endif