xref: /titanic_41/usr/src/cmd/lvm/metassist/controller/getopt_ext.h (revision 4a6ec905b96eb96a398c346f59e034a90ce8ad37)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _GETOPTEXT_H
28 #define	_GETOPTEXT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Returned chars for getopt_ext
38  */
39 
40 /* A non-option argument was found */
41 #define	GETOPT_NON_OPTION_ARG		1
42 
43 /* All arguments have been parsed */
44 #define	GETOPT_DONE_PARSING		-1
45 
46 /* An invalid option was found */
47 #define	GETOPT_ERR_INVALID_OPT		-2
48 
49 /* An invalid non-option argument was found */
50 #define	GETOPT_ERR_INVALID_ARG		-3
51 
52 /* No argument for valid option expecting an argument */
53 #define	GETOPT_ERR_MISSING_ARG		-4
54 
55 /*
56  * Function prototypes
57  */
58 
59 /*
60  * Identical to getopt(3), except that
61  *
62  * 1. If "-" is the first character of optstring, each non-option argv
63  *    element is handled as if it were the argument of an option with
64  *    character code GETOPT_NON_OPTION_ARG.  The result is that
65  *    GETOPT_DONE_PARSING will not be returned until the end of the
66  *    argument list has been reached.
67  *
68  *    This mirrors the functionality provided by GNU getopt.
69  *
70  * 2. GETOPT_ERR_INVALID_OPT or GETOPT_ERR_MISSING_ARG is returned
71  *    instead of '?'.  Subsequently "-?" can be used as a valid
72  *    option.
73  *
74  * 3. GETOPT_DONE_PARSING, GETOPT_ERR_INVALID_ARG, or
75  *    GETOPT_NON_OPTION_ARG is returned instead of -1.
76  *
77  * @param       argc
78  *              The number of arguments in the array
79  *
80  * @param       argv
81  *              The argument array
82  *
83  * @param       optstring
84  *              The option letters, with ':' following options with
85  *              required arguments.  See note about "-" as the first
86  *              character.
87  *
88  * @return      GETOPT_ERR_INVALID_OPT
89  *              if the option is not found in optstring
90  *
91  *              GETOPT_ERR_MISSING_ARG
92  *              if the option requires an argument which is missing
93  *
94  *              GETOPT_ERR_INVALID_ARG
95  *              if "-" is not the first character in optstring and a
96  *              non-option argument is encountered
97  *
98  *              GETOPT_NON_OPTION_ARG
99  *              if "-" is the first character in optstring and a
100  *              non-option argument is encountered
101  *
102  *              GETOPT_DONE_PARSING
103  *              if the end of the argument list is reached
104  *
105  *              <optopt>
106  *              the option character itself, if none of the above
107  *              scenarios applies.
108  */
109 extern int getopt_ext(int argc, char * const argv[], const char *optstring);
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif /* _GETOPTEXT_H */
116