10b57cec5SDimitry Andric //===-- GetOptInc.h ---------------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLDB_HOST_COMMON_GETOPTINC_H
100b57cec5SDimitry Andric #define LLDB_HOST_COMMON_GETOPTINC_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "lldb/lldb-defines.h"
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #if defined(_MSC_VER)
150b57cec5SDimitry Andric #define REPLACE_GETOPT
160b57cec5SDimitry Andric #define REPLACE_GETOPT_LONG
170b57cec5SDimitry Andric #endif
180b57cec5SDimitry Andric #if defined(_MSC_VER) || defined(__NetBSD__)
190b57cec5SDimitry Andric #define REPLACE_GETOPT_LONG_ONLY
200b57cec5SDimitry Andric #endif
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric #if defined(REPLACE_GETOPT)
230b57cec5SDimitry Andric // from getopt.h
240b57cec5SDimitry Andric #define no_argument 0
250b57cec5SDimitry Andric #define required_argument 1
260b57cec5SDimitry Andric #define optional_argument 2
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric // option structure
290b57cec5SDimitry Andric struct option {
300b57cec5SDimitry Andric   const char *name;
310b57cec5SDimitry Andric   // has_arg can't be an enum because some compilers complain about type
320b57cec5SDimitry Andric   // mismatches in all the code that assumes it is an int.
330b57cec5SDimitry Andric   int has_arg;
340b57cec5SDimitry Andric   int *flag;
350b57cec5SDimitry Andric   int val;
360b57cec5SDimitry Andric };
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric int getopt(int argc, char *const argv[], const char *optstring);
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric // from getopt.h
410b57cec5SDimitry Andric extern char *optarg;
420b57cec5SDimitry Andric extern int optind;
430b57cec5SDimitry Andric extern int opterr;
440b57cec5SDimitry Andric extern int optopt;
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric // defined in unistd.h
470b57cec5SDimitry Andric extern int optreset;
480b57cec5SDimitry Andric #else
490b57cec5SDimitry Andric #include <getopt.h>
500b57cec5SDimitry Andric #include <unistd.h>
510b57cec5SDimitry Andric #endif
520b57cec5SDimitry Andric 
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