Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include "lldb/lldb-defines.h" |
| 4 | |
| 5 | #if defined(_MSC_VER) |
| 6 | #define REPLACE_GETOPT |
| 7 | #define REPLACE_GETOPT_LONG |
| 8 | #endif |
| 9 | #if defined(_MSC_VER) || defined(__NetBSD__) |
| 10 | #define REPLACE_GETOPT_LONG_ONLY |
| 11 | #endif |
| 12 | |
| 13 | #if defined(REPLACE_GETOPT) |
| 14 | // from getopt.h |
| 15 | #define no_argument 0 |
| 16 | #define required_argument 1 |
| 17 | #define optional_argument 2 |
| 18 | |
| 19 | // option structure |
| 20 | struct option { |
| 21 | const char *name; |
| 22 | // has_arg can't be an enum because some compilers complain about type |
| 23 | // mismatches in all the code that assumes it is an int. |
| 24 | int has_arg; |
| 25 | int *flag; |
| 26 | int val; |
| 27 | }; |
| 28 | |
| 29 | int getopt(int argc, char *const argv[], const char *optstring); |
| 30 | |
| 31 | // from getopt.h |
| 32 | extern char *optarg; |
| 33 | extern int optind; |
| 34 | extern int opterr; |
| 35 | extern int optopt; |
| 36 | |
| 37 | // defined in unistd.h |
| 38 | extern int optreset; |
| 39 | #else |
| 40 | #include <getopt.h> |
| 41 | #include <unistd.h> |
| 42 | #endif |
| 43 | |
| 44 | #if defined(REPLACE_GETOPT_LONG) |
| 45 | int getopt_long(int argc, char *const *argv, const char *optstring, |
| 46 | const struct option *longopts, int *longindex); |
| 47 | #endif |
| 48 | |
| 49 | #if defined(REPLACE_GETOPT_LONG_ONLY) |
| 50 | int getopt_long_only(int argc, char *const *argv, const char *optstring, |
| 51 | const struct option *longopts, int *longindex); |
| 52 | #endif |