getopt.h revision 126155
1104128Seric/*	$NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $	*/
2104128Seric/*	$FreeBSD: head/include/getopt.h 126155 2004-02-23 08:14:18Z ache $ */
3104128Seric
4104128Seric/*-
5104128Seric * Copyright (c) 2000 The NetBSD Foundation, Inc.
6104128Seric * All rights reserved.
7104128Seric *
8104128Seric * This code is derived from software contributed to The NetBSD Foundation
9104128Seric * by Dieter Baron and Thomas Klausner.
10104128Seric *
11104128Seric * Redistribution and use in source and binary forms, with or without
12104128Seric * modification, are permitted provided that the following conditions
13104128Seric * are met:
14104128Seric * 1. Redistributions of source code must retain the above copyright
15104128Seric *    notice, this list of conditions and the following disclaimer.
16104128Seric * 2. Redistributions in binary form must reproduce the above copyright
17104128Seric *    notice, this list of conditions and the following disclaimer in the
18104128Seric *    documentation and/or other materials provided with the distribution.
19104128Seric * 3. All advertising materials mentioning features or use of this software
20104128Seric *    must display the following acknowledgement:
21104128Seric *        This product includes software developed by the NetBSD
22104128Seric *        Foundation, Inc. and its contributors.
23104128Seric * 4. Neither the name of The NetBSD Foundation nor the names of its
24104128Seric *    contributors may be used to endorse or promote products derived
25104128Seric *    from this software without specific prior written permission.
26104128Seric *
27104128Seric * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28104128Seric * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29104128Seric * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30104128Seric * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31104128Seric * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32104128Seric * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33104128Seric * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34104128Seric * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35104128Seric * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36104128Seric * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37104128Seric * POSSIBILITY OF SUCH DAMAGE.
38104128Seric */
39104128Seric
40104128Seric#ifndef _GETOPT_H_
41104128Seric#define _GETOPT_H_
42104128Seric
43104128Seric#include <sys/cdefs.h>
44104128Seric
45104128Seric/*
46126155Sache * GNU-like getopt_long() with 4.4BSD optreset extension.
47126155Sache * getopt() is declared here too for GNU programs.
48104128Seric */
49104128Seric#define no_argument        0
50104128Seric#define required_argument  1
51104128Seric#define optional_argument  2
52104128Seric
53104128Sericstruct option {
54104128Seric	/* name of long option */
55104128Seric	const char *name;
56104128Seric	/*
57104128Seric	 * one of no_argument, required_argument, and optional_argument:
58104128Seric	 * whether option takes an argument
59104128Seric	 */
60104128Seric	int has_arg;
61104128Seric	/* if not NULL, set *flag to val when option found */
62104128Seric	int *flag;
63104128Seric	/* if flag not NULL, value to set *flag to; else return value */
64104128Seric	int val;
65104128Seric};
66104128Seric
67104128Seric__BEGIN_DECLS
68126141Sacheint	getopt_long(int, char * const *, const char *,
69126141Sache	const struct option *, int *);
70126141Sache#ifndef _GETOPT_DECLARED
71126141Sache#define	_GETOPT_DECLARED
72126141Sacheint	 getopt(int, char * const [], const char *);
73126141Sache
74126141Sacheextern char *optarg;			/* getopt(3) external variables */
75126141Sacheextern int optind, opterr, optopt;
76126142Sache#endif
77126142Sache#ifndef _OPTRESET_DECLARED
78126142Sache#define	_OPTRESET_DECLARED
79126142Sacheextern int optreset;			/* getopt(3) external variable */
80126142Sache#endif
81104128Seric__END_DECLS
82104128Seric
83104128Seric#endif /* !_GETOPT_H_ */
84