gen-strtab.awk: Fix strings that start with octal digits.
[dxcommon.git] / src / gnu_getopt.h
blob1d61eba477914453a79357422924878ba81a476f
1 /*
2 * Portability wrapper to provide <getopt.h> declarations when the
3 * system is missing them.
5 * Copyright © 2024 Nick Bowler
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * If either HAVE_GETOPT_LONG or HAVE_GETOPT_LONG_ONLY are defined to 1,
23 * then the system <getopt.h> is used to get a declaration of struct
24 * option and the global getopt variables. If neither are defined,
25 * then <getopt.h> is not included and replacements are provided.
27 * These replacements will interfere with POSIX getopt which uses the
28 * same variable names so that cannot be used at the same time. For
29 * the same reason, do not use both getopt_long and getopt_long_only
30 * in the same program, as some systems provide one but not both.
33 #ifndef DX_GETOPT_H_
34 #define DX_GETOPT_H_
36 #if HAVE_GETOPT_LONG || HAVE_GETOPT_LONG_ONLY
37 # include <getopt.h>
38 #else
39 struct option {
40 const char *name;
41 int has_arg, *flag, val;
44 extern int optind, optopt, opterr;
45 extern char *optarg;
46 #endif
48 /* Local fallback implementation */
49 int gnu_getopt(int, char **, const char *, const struct option *, int *, int);
51 #if !HAVE_GETOPT_LONG
52 #define getopt_long(argc, argv, sopts, lopts, idx) \
53 gnu_getopt(argc, argv, sopts, lopts, idx, 0)
54 #endif
56 #if !HAVE_GETOPT_LONG_ONLY
57 #define getopt_long_only(argc, argv, sopts, lopts, idx) \
58 gnu_getopt(argc, argv, sopts, lopts, idx, 1)
59 #endif
61 #endif