1*193032a3SAndroid Build Coastguard Worker /** 2*193032a3SAndroid Build Coastguard Worker * @file getopt.h 3*193032a3SAndroid Build Coastguard Worker * @copy 2012 MinGW.org project 4*193032a3SAndroid Build Coastguard Worker * 5*193032a3SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a 6*193032a3SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"), 7*193032a3SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation 8*193032a3SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9*193032a3SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the 10*193032a3SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions: 11*193032a3SAndroid Build Coastguard Worker * 12*193032a3SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the next 13*193032a3SAndroid Build Coastguard Worker * paragraph) shall be included in all copies or substantial portions of the 14*193032a3SAndroid Build Coastguard Worker * Software. 15*193032a3SAndroid Build Coastguard Worker * 16*193032a3SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17*193032a3SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18*193032a3SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19*193032a3SAndroid Build Coastguard Worker * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20*193032a3SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21*193032a3SAndroid Build Coastguard Worker * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22*193032a3SAndroid Build Coastguard Worker * DEALINGS IN THE SOFTWARE. 23*193032a3SAndroid Build Coastguard Worker */ 24*193032a3SAndroid Build Coastguard Worker #ifndef _GETOPT_H 25*193032a3SAndroid Build Coastguard Worker #define _GETOPT_H 26*193032a3SAndroid Build Coastguard Worker 27*193032a3SAndroid Build Coastguard Worker /* 28*193032a3SAndroid Build Coastguard Worker * Defines constants and function prototypes required to implement 29*193032a3SAndroid Build Coastguard Worker * the `getopt', `getopt_long' and `getopt_long_only' APIs. 30*193032a3SAndroid Build Coastguard Worker */ 31*193032a3SAndroid Build Coastguard Worker 32*193032a3SAndroid Build Coastguard Worker #ifdef __cplusplus 33*193032a3SAndroid Build Coastguard Worker extern "C" { 34*193032a3SAndroid Build Coastguard Worker #endif 35*193032a3SAndroid Build Coastguard Worker 36*193032a3SAndroid Build Coastguard Worker extern int optind; /* index of first non-option in argv */ 37*193032a3SAndroid Build Coastguard Worker extern int optopt; /* single option character, as parsed */ 38*193032a3SAndroid Build Coastguard Worker extern int opterr; /* flag to enable built-in diagnostics... */ 39*193032a3SAndroid Build Coastguard Worker /* (user may set to zero, to suppress) */ 40*193032a3SAndroid Build Coastguard Worker 41*193032a3SAndroid Build Coastguard Worker extern char *optarg; /* pointer to argument of current option */ 42*193032a3SAndroid Build Coastguard Worker 43*193032a3SAndroid Build Coastguard Worker extern int getopt( int, char * const [], const char * ); 44*193032a3SAndroid Build Coastguard Worker 45*193032a3SAndroid Build Coastguard Worker #ifdef _BSD_SOURCE 46*193032a3SAndroid Build Coastguard Worker /* 47*193032a3SAndroid Build Coastguard Worker * BSD adds the non-standard `optreset' feature, for reinitialisation 48*193032a3SAndroid Build Coastguard Worker * of `getopt' parsing. We support this feature, for applications which 49*193032a3SAndroid Build Coastguard Worker * proclaim their BSD heritage, before including this header; however, 50*193032a3SAndroid Build Coastguard Worker * to maintain portability, developers are advised to avoid it. 51*193032a3SAndroid Build Coastguard Worker */ 52*193032a3SAndroid Build Coastguard Worker # define optreset __mingw_optreset 53*193032a3SAndroid Build Coastguard Worker 54*193032a3SAndroid Build Coastguard Worker extern int optreset; 55*193032a3SAndroid Build Coastguard Worker #endif 56*193032a3SAndroid Build Coastguard Worker #ifdef __cplusplus 57*193032a3SAndroid Build Coastguard Worker } 58*193032a3SAndroid Build Coastguard Worker #endif 59*193032a3SAndroid Build Coastguard Worker /* 60*193032a3SAndroid Build Coastguard Worker * POSIX requires the `getopt' API to be specified in `unistd.h'; 61*193032a3SAndroid Build Coastguard Worker * thus, `unistd.h' includes this header. However, we do not want 62*193032a3SAndroid Build Coastguard Worker * to expose the `getopt_long' or `getopt_long_only' APIs, when 63*193032a3SAndroid Build Coastguard Worker * included in this manner. Thus, close the standard __GETOPT_H__ 64*193032a3SAndroid Build Coastguard Worker * declarations block, and open an additional __GETOPT_LONG_H__ 65*193032a3SAndroid Build Coastguard Worker * specific block, only when *not* __UNISTD_H_SOURCED__, in which 66*193032a3SAndroid Build Coastguard Worker * to declare the extended API. 67*193032a3SAndroid Build Coastguard Worker */ 68*193032a3SAndroid Build Coastguard Worker #endif /* !defined(__GETOPT_H__) */ 69*193032a3SAndroid Build Coastguard Worker #if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) 70*193032a3SAndroid Build Coastguard Worker #define __GETOPT_LONG_H__ 71*193032a3SAndroid Build Coastguard Worker 72*193032a3SAndroid Build Coastguard Worker #ifdef __cplusplus 73*193032a3SAndroid Build Coastguard Worker extern "C" { 74*193032a3SAndroid Build Coastguard Worker #endif 75*193032a3SAndroid Build Coastguard Worker 76*193032a3SAndroid Build Coastguard Worker struct option /* specification for a long form option... */ 77*193032a3SAndroid Build Coastguard Worker { 78*193032a3SAndroid Build Coastguard Worker const char *name; /* option name, without leading hyphens */ 79*193032a3SAndroid Build Coastguard Worker int has_arg; /* does it take an argument? */ 80*193032a3SAndroid Build Coastguard Worker int *flag; /* where to save its status, or NULL */ 81*193032a3SAndroid Build Coastguard Worker int val; /* its associated status value */ 82*193032a3SAndroid Build Coastguard Worker }; 83*193032a3SAndroid Build Coastguard Worker 84*193032a3SAndroid Build Coastguard Worker enum /* permitted values for its `has_arg' field... */ 85*193032a3SAndroid Build Coastguard Worker { 86*193032a3SAndroid Build Coastguard Worker no_argument = 0, /* option never takes an argument */ 87*193032a3SAndroid Build Coastguard Worker required_argument, /* option always requires an argument */ 88*193032a3SAndroid Build Coastguard Worker optional_argument /* option may take an argument */ 89*193032a3SAndroid Build Coastguard Worker }; 90*193032a3SAndroid Build Coastguard Worker 91*193032a3SAndroid Build Coastguard Worker extern int getopt_long( int, char * const [], const char *, const struct option *, int * ); 92*193032a3SAndroid Build Coastguard Worker extern int getopt_long_only( int, char * const [], const char *, const struct option *, int * ); 93*193032a3SAndroid Build Coastguard Worker /* 94*193032a3SAndroid Build Coastguard Worker * Previous MinGW implementation had... 95*193032a3SAndroid Build Coastguard Worker */ 96*193032a3SAndroid Build Coastguard Worker #ifndef HAVE_DECL_GETOPT 97*193032a3SAndroid Build Coastguard Worker /* 98*193032a3SAndroid Build Coastguard Worker * ...for the long form API only; keep this for compatibility. 99*193032a3SAndroid Build Coastguard Worker */ 100*193032a3SAndroid Build Coastguard Worker # define HAVE_DECL_GETOPT 1 101*193032a3SAndroid Build Coastguard Worker #endif 102*193032a3SAndroid Build Coastguard Worker 103*193032a3SAndroid Build Coastguard Worker #ifdef __cplusplus 104*193032a3SAndroid Build Coastguard Worker } 105*193032a3SAndroid Build Coastguard Worker #endif 106*193032a3SAndroid Build Coastguard Worker 107*193032a3SAndroid Build Coastguard Worker #endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */ 108