eal/windows: add getopt implementation
[dpdk.git] / lib / librte_eal / windows / eal / include / getopt.h
1 /* SPDX-License-Identifier: BSD-2-Clause
2  * Copyright (c) 2000 The NetBSD Foundation, Inc.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to The NetBSD Foundation
6  * by Dieter Baron and Thomas Klausner.
7  */
8
9 /**
10  * @file
11  * getopt compat.
12  *
13  * This module provides getopt() and getopt_long().
14  */
15
16 #ifndef _USUAL_GETOPT_H_
17 #define _USUAL_GETOPT_H_
18
19 #ifndef NEED_USUAL_GETOPT
20 #if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT) || \
21         !defined(HAVE_GETOPT_LONG)
22 #define NEED_USUAL_GETOPT
23 #endif
24 #endif
25
26 #ifndef NEED_USUAL_GETOPT
27
28 /* Use system getopt */
29 #include <getopt.h>
30
31 #else /* NEED_USUAL_GETOPT */
32
33 /* avoid name collision */
34 #define optarg usual_optarg
35 #define opterr usual_opterr
36 #define optind usual_optind
37 #define optopt usual_optopt
38 #define getopt(a, b, c) usual_getopt(a, b, c)
39 #define getopt_long(a, b, c, d, e) usual_getopt_long(a, b, c, d, e)
40
41
42 /** argument to current option, or NULL if it has none */
43 extern const char *optarg;
44 /** Current position in arg string.  Starts from 1.
45  * Setting to 0 resets state.
46  */
47 extern int optind;
48 /** whether getopt() should print error messages on problems.  Default: 1. */
49 extern int opterr;
50 /** Option char which caused error */
51 extern int optopt;
52
53 /** long option takes no argument */
54 #define no_argument        0
55 /** long option requires argument */
56 #define required_argument  1
57 /** long option has optional argument */
58 #define optional_argument  2
59
60 /** Long option description */
61 struct option {
62         /** name of long option */
63         const char *name;
64
65         /**
66          * whether option takes an argument.
67          * One of no_argument, required_argument, and optional_argument.
68          */
69         int has_arg;
70
71         /** if not NULL, set *flag to val when option found */
72         int *flag;
73
74         /** if flag not NULL, value to set *flag to; else return value */
75         int val;
76 };
77
78 /** Compat: getopt */
79 int getopt(int argc, char *argv[], const char *options);
80
81 /** Compat: getopt_long */
82 int getopt_long(int argc, char *argv[], const char *options,
83                 const struct option *longopts, int *longindex);
84
85 /** Compat: getopt_long_only */
86 int getopt_long_only(int nargc, char *argv[], const char *options,
87                      const struct option *long_options, int *idx);
88
89
90 #endif /* NEED_USUAL_GETOPT */
91
92 #endif /* !_USUAL_GETOPT_H_ */