getopt.h revision 267654
1224090Sdougb/*	$NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $	*/
2254402Serwin/*	$FreeBSD: releng/9.3/include/getopt.h 203963 2010-02-16 19:28:10Z imp $ */
3224090Sdougb
4224090Sdougb/*-
5224090Sdougb * Copyright (c) 2000 The NetBSD Foundation, Inc.
6224090Sdougb * All rights reserved.
7224090Sdougb *
8224090Sdougb * This code is derived from software contributed to The NetBSD Foundation
9224090Sdougb * by Dieter Baron and Thomas Klausner.
10224090Sdougb *
11224090Sdougb * Redistribution and use in source and binary forms, with or without
12224090Sdougb * modification, are permitted provided that the following conditions
13224090Sdougb * are met:
14224090Sdougb * 1. Redistributions of source code must retain the above copyright
15224090Sdougb *    notice, this list of conditions and the following disclaimer.
16224090Sdougb * 2. Redistributions in binary form must reproduce the above copyright
17254897Serwin *    notice, this list of conditions and the following disclaimer in the
18224090Sdougb *    documentation and/or other materials provided with the distribution.
19224090Sdougb *
20224090Sdougb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21224090Sdougb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22224090Sdougb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23224090Sdougb * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24224090Sdougb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25224090Sdougb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26224090Sdougb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27224090Sdougb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28224090Sdougb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29224090Sdougb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30224090Sdougb * POSSIBILITY OF SUCH DAMAGE.
31224090Sdougb */
32224090Sdougb
33224090Sdougb#ifndef _GETOPT_H_
34224090Sdougb#define _GETOPT_H_
35224090Sdougb
36224090Sdougb#include <sys/cdefs.h>
37224090Sdougb
38224090Sdougb/*
39224090Sdougb * GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension.
40224090Sdougb * getopt() is declared here too for GNU programs.
41224090Sdougb */
42224090Sdougb#define no_argument        0
43224090Sdougb#define required_argument  1
44224090Sdougb#define optional_argument  2
45224090Sdougb
46224090Sdougbstruct option {
47224090Sdougb	/* name of long option */
48224090Sdougb	const char *name;
49224090Sdougb	/*
50224090Sdougb	 * one of no_argument, required_argument, and optional_argument:
51224090Sdougb	 * whether option takes an argument
52224090Sdougb	 */
53224090Sdougb	int has_arg;
54224090Sdougb	/* if not NULL, set *flag to val when option found */
55224090Sdougb	int *flag;
56224090Sdougb	/* if flag not NULL, value to set *flag to; else return value */
57224090Sdougb	int val;
58224090Sdougb};
59224090Sdougb
60224090Sdougb__BEGIN_DECLS
61224090Sdougbint	getopt_long(int, char * const *, const char *,
62224090Sdougb	const struct option *, int *);
63224090Sdougbint	getopt_long_only(int, char * const *, const char *,
64224090Sdougb	const struct option *, int *);
65224090Sdougb#ifndef _GETOPT_DECLARED
66224090Sdougb#define	_GETOPT_DECLARED
67224090Sdougbint	 getopt(int, char * const [], const char *);
68224090Sdougb
69224090Sdougbextern char *optarg;			/* getopt(3) external variables */
70224090Sdougbextern int optind, opterr, optopt;
71224090Sdougb#endif
72224090Sdougb#ifndef _OPTRESET_DECLARED
73224090Sdougb#define	_OPTRESET_DECLARED
74224090Sdougbextern int optreset;			/* getopt(3) external variable */
75224090Sdougb#endif
76224090Sdougb__END_DECLS
77224090Sdougb
78224090Sdougb#endif /* !_GETOPT_H_ */
79224090Sdougb