aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Host/common/GetOptInc.h
blob: f79644017ca54889c2e2e0b9c4c98af4cb49aa06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once

#include "lldb/lldb-defines.h"

#if defined(_MSC_VER)
#define REPLACE_GETOPT
#define REPLACE_GETOPT_LONG
#endif
#if defined(_MSC_VER) || defined(__NetBSD__)
#define REPLACE_GETOPT_LONG_ONLY
#endif

#if defined(REPLACE_GETOPT)
// from getopt.h
#define no_argument       0
#define required_argument 1
#define optional_argument 2

// option structure
struct option
{
    const char *name;
    // has_arg can't be an enum because some compilers complain about
    // type mismatches in all the code that assumes it is an int.
    int  has_arg;
    int *flag;
    int  val;
};

int getopt( int argc, char * const argv[], const char *optstring );

// from getopt.h
extern char * optarg;
extern int    optind;
extern int    opterr;
extern int    optopt;

// defined in unistd.h
extern int    optreset;
#else
# include <unistd.h>
# include <getopt.h>
#endif

#if defined(REPLACE_GETOPT_LONG)
int getopt_long
(
    int argc,
    char * const *argv,
    const char *optstring,
    const struct option *longopts,
    int *longindex
);
#endif

#if defined(REPLACE_GETOPT_LONG_ONLY)
int getopt_long_only
(
    int argc,
    char * const *argv,
    const char *optstring,
    const struct option *longopts,
    int *longindex
);
#endif