1 //===-- GetOptInc.h ---------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_HOST_COMMON_GETOPTINC_H
10 #define LLDB_HOST_COMMON_GETOPTINC_H
11 
12 #include "lldb/lldb-defines.h"
13 
14 #if defined(_MSC_VER)
15 #define REPLACE_GETOPT
16 #define REPLACE_GETOPT_LONG
17 #endif
18 #if defined(_MSC_VER) || defined(__NetBSD__)
19 #define REPLACE_GETOPT_LONG_ONLY
20 #endif
21 
22 #if defined(REPLACE_GETOPT)
23 // from getopt.h
24 #define no_argument 0
25 #define required_argument 1
26 #define optional_argument 2
27 
28 // option structure
29 struct option {
30   const char *name;
31   // has_arg can't be an enum because some compilers complain about type
32   // mismatches in all the code that assumes it is an int.
33   int has_arg;
34   int *flag;
35   int val;
36 };
37 
38 int getopt(int argc, char *const argv[], const char *optstring);
39 
40 // from getopt.h
41 extern char *optarg;
42 extern int optind;
43 extern int opterr;
44 extern int optopt;
45 
46 // defined in unistd.h
47 extern int optreset;
48 #else
49 #include <getopt.h>
50 #include <unistd.h>
51 #endif
52 
53 #if defined(REPLACE_GETOPT_LONG)
54 int getopt_long(int argc, char *const *argv, const char *optstring,
55                 const struct option *longopts, int *longindex);
56 #endif
57 
58 #if defined(REPLACE_GETOPT_LONG_ONLY)
59 int getopt_long_only(int argc, char *const *argv, const char *optstring,
60                      const struct option *longopts, int *longindex);
61 #endif
62 
63 #endif // LLDB_HOST_COMMON_GETOPTINC_H
64