blob: c69f7227a5cf8ed1e2509cdacc083766330b2a24 [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001#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
20struct 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
29int getopt(int argc, char *const argv[], const char *optstring);
30
31// from getopt.h
32extern char *optarg;
33extern int optind;
34extern int opterr;
35extern int optopt;
36
37// defined in unistd.h
38extern int optreset;
39#else
40#include <getopt.h>
41#include <unistd.h>
42#endif
43
44#if defined(REPLACE_GETOPT_LONG)
45int 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)
50int getopt_long_only(int argc, char *const *argv, const char *optstring,
51 const struct option *longopts, int *longindex);
52#endif