1 #ifndef __GETOPT_H__
2 /**
3  * DISCLAIMER
4  * This file has no copyright assigned and is placed in the Public Domain.
5  * This file is a part of the w64 mingw-runtime package.
6  *
7  * The w64 mingw-runtime package and its code is distributed in the hope that it
8  * will be useful but WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESSED OR
9  * IMPLIED ARE HEREBY DISCLAIMED.  This includes but is not limited to
10  * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 #define __GETOPT_H__
14 
15 /* All the headers include this file. */
16 #include <crtdefs.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 extern int optind;		/* index of first non-option in argv      */
23 extern int optopt;		/* single option character, as parsed     */
24 extern int opterr;		/* flag to enable built-in diagnostics... */
25 				/* (user may set to zero, to suppress)    */
26 
27 extern char *optarg;		/* pointer to argument of current option  */
28 
29 extern int getopt(int nargc, char * const *nargv, const char *options);
30 
31 #ifdef _BSD_SOURCE
32 /*
33  * BSD adds the non-standard `optreset' feature, for reinitialisation
34  * of `getopt' parsing.  We support this feature, for applications which
35  * proclaim their BSD heritage, before including this header; however,
36  * to maintain portability, developers are advised to avoid it.
37  */
38 # define optreset  __mingw_optreset
39 extern int optreset;
40 #endif
41 #ifdef __cplusplus
42 }
43 #endif
44 /*
45  * POSIX requires the `getopt' API to be specified in `unistd.h';
46  * thus, `unistd.h' includes this header.  However, we do not want
47  * to expose the `getopt_long' or `getopt_long_only' APIs, when
48  * included in this manner.  Thus, close the standard __GETOPT_H__
49  * declarations block, and open an additional __GETOPT_LONG_H__
50  * specific block, only when *not* __UNISTD_H_SOURCED__, in which
51  * to declare the extended API.
52  */
53 #endif /* !defined(__GETOPT_H__) */
54 
55 #if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)
56 #define __GETOPT_LONG_H__
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 struct option		/* specification for a long form option...	*/
63 {
64   const char *name;		/* option name, without leading hyphens */
65   int         has_arg;		/* does it take an argument?		*/
66   int        *flag;		/* where to save its status, or NULL	*/
67   int         val;		/* its associated status value		*/
68 };
69 
70 enum    		/* permitted values for its `has_arg' field...	*/
71 {
72   no_argument = 0,      	/* option never takes an argument	*/
73   required_argument,		/* option always requires an argument	*/
74   optional_argument		/* option may take an argument		*/
75 };
76 
77 extern int getopt_long(int nargc, char * const *nargv, const char *options,
78     const struct option *long_options, int *idx);
79 extern int getopt_long_only(int nargc, char * const *nargv, const char *options,
80     const struct option *long_options, int *idx);
81 /*
82  * Previous MinGW implementation had...
83  */
84 #ifndef HAVE_DECL_GETOPT
85 /*
86  * ...for the long form API only; keep this for compatibility.
87  */
88 # define HAVE_DECL_GETOPT	1
89 #endif
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */
96