1 /* SPDX-License-Identifier: BSD-2-Clause
2 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Dieter Baron and Thomas Klausner.
13 * This module provides getopt() and getopt_long().
16 #ifndef _USUAL_GETOPT_H_
17 #define _USUAL_GETOPT_H_
19 #ifndef NEED_USUAL_GETOPT
20 #if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT) || \
21 !defined(HAVE_GETOPT_LONG)
22 #define NEED_USUAL_GETOPT
26 #ifndef NEED_USUAL_GETOPT
28 /* Use system getopt */
31 #else /* NEED_USUAL_GETOPT */
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)
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.
48 /** whether getopt() should print error messages on problems. Default: 1. */
50 /** Option char which caused error */
53 /** long option takes no argument */
55 /** long option requires argument */
56 #define required_argument 1
57 /** long option has optional argument */
58 #define optional_argument 2
60 /** Long option description */
62 /** name of long option */
66 * whether option takes an argument.
67 * One of no_argument, required_argument, and optional_argument.
71 /** if not NULL, set *flag to val when option found */
74 /** if flag not NULL, value to set *flag to; else return value */
79 int getopt(int argc, char *argv[], const char *options);
81 /** Compat: getopt_long */
82 int getopt_long(int argc, char *argv[], const char *options,
83 const struct option *longopts, int *longindex);
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);
90 #endif /* NEED_USUAL_GETOPT */
92 #endif /* !_USUAL_GETOPT_H_ */