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