xref: /netbsd-src/include/getopt.h (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /*	$NetBSD: getopt.h,v 1.11 2008/04/28 20:22:54 martin Exp $	*/
2a91d8b9eSchristos 
3a91d8b9eSchristos /*-
4a91d8b9eSchristos  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5a91d8b9eSchristos  * All rights reserved.
6a91d8b9eSchristos  *
7a91d8b9eSchristos  * This code is derived from software contributed to The NetBSD Foundation
8a91d8b9eSchristos  * by Dieter Baron and Thomas Klausner.
9a91d8b9eSchristos  *
10a91d8b9eSchristos  * Redistribution and use in source and binary forms, with or without
11a91d8b9eSchristos  * modification, are permitted provided that the following conditions
12a91d8b9eSchristos  * are met:
13a91d8b9eSchristos  * 1. Redistributions of source code must retain the above copyright
14a91d8b9eSchristos  *    notice, this list of conditions and the following disclaimer.
15a91d8b9eSchristos  * 2. Redistributions in binary form must reproduce the above copyright
16a91d8b9eSchristos  *    notice, this list of conditions and the following disclaimer in the
17a91d8b9eSchristos  *    documentation and/or other materials provided with the distribution.
18a91d8b9eSchristos  *
19a91d8b9eSchristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20a91d8b9eSchristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21a91d8b9eSchristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22a91d8b9eSchristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23a91d8b9eSchristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24a91d8b9eSchristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25a91d8b9eSchristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26a91d8b9eSchristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27a91d8b9eSchristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28a91d8b9eSchristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29a91d8b9eSchristos  * POSSIBILITY OF SUCH DAMAGE.
30a91d8b9eSchristos  */
31813b1610Sad 
32a91d8b9eSchristos #ifndef _GETOPT_H_
33a91d8b9eSchristos #define _GETOPT_H_
34a91d8b9eSchristos 
35813b1610Sad #include <sys/cdefs.h>
36d99720e2Schristos #include <unistd.h>
37813b1610Sad 
38a91d8b9eSchristos /*
39a91d8b9eSchristos  * Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions
40a91d8b9eSchristos  */
41a91d8b9eSchristos #define no_argument        0
42a91d8b9eSchristos #define required_argument  1
43a91d8b9eSchristos #define optional_argument  2
44a91d8b9eSchristos 
45a91d8b9eSchristos struct option {
46a91d8b9eSchristos 	/* name of long option */
47a91d8b9eSchristos 	const char *name;
48a91d8b9eSchristos 	/*
49a91d8b9eSchristos 	 * one of no_argument, required_argument, and optional_argument:
50a91d8b9eSchristos 	 * whether option takes an argument
51a91d8b9eSchristos 	 */
52a91d8b9eSchristos 	int has_arg;
53a91d8b9eSchristos 	/* if not NULL, set *flag to val when option found */
54a91d8b9eSchristos 	int *flag;
55a91d8b9eSchristos 	/* if flag not NULL, value to set *flag to; else return value */
56a91d8b9eSchristos 	int val;
57a91d8b9eSchristos };
58a91d8b9eSchristos 
59a91d8b9eSchristos __BEGIN_DECLS
6019b7469aSperry int getopt_long(int, char * const *, const char *,
6119b7469aSperry     const struct option *, int *);
62a91d8b9eSchristos __END_DECLS
63a91d8b9eSchristos 
64a91d8b9eSchristos #endif /* !_GETOPT_H_ */
65