xref: /openbsd/include/getopt.h (revision 6290d6db)
1*6290d6dbSmillert /*	$OpenBSD: getopt.h,v 1.3 2013/11/22 21:32:49 millert Exp $	*/
247f6c619Smillert /*	$NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $	*/
347f6c619Smillert 
447f6c619Smillert /*-
547f6c619Smillert  * Copyright (c) 2000 The NetBSD Foundation, Inc.
647f6c619Smillert  * All rights reserved.
747f6c619Smillert  *
847f6c619Smillert  * This code is derived from software contributed to The NetBSD Foundation
947f6c619Smillert  * by Dieter Baron and Thomas Klausner.
1047f6c619Smillert  *
1147f6c619Smillert  * Redistribution and use in source and binary forms, with or without
1247f6c619Smillert  * modification, are permitted provided that the following conditions
1347f6c619Smillert  * are met:
1447f6c619Smillert  * 1. Redistributions of source code must retain the above copyright
1547f6c619Smillert  *    notice, this list of conditions and the following disclaimer.
1647f6c619Smillert  * 2. Redistributions in binary form must reproduce the above copyright
1747f6c619Smillert  *    notice, this list of conditions and the following disclaimer in the
1847f6c619Smillert  *    documentation and/or other materials provided with the distribution.
1947f6c619Smillert  *
2047f6c619Smillert  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2147f6c619Smillert  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2247f6c619Smillert  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2347f6c619Smillert  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2447f6c619Smillert  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2547f6c619Smillert  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2647f6c619Smillert  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2747f6c619Smillert  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2847f6c619Smillert  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2947f6c619Smillert  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3047f6c619Smillert  * POSSIBILITY OF SUCH DAMAGE.
3147f6c619Smillert  */
3247f6c619Smillert 
3347f6c619Smillert #ifndef _GETOPT_H_
3447f6c619Smillert #define _GETOPT_H_
3547f6c619Smillert 
3647f6c619Smillert #include <sys/cdefs.h>
3747f6c619Smillert 
3847f6c619Smillert /*
39*6290d6dbSmillert  * GNU-like getopt_long()
4047f6c619Smillert  */
4147f6c619Smillert #define no_argument        0
4247f6c619Smillert #define required_argument  1
4347f6c619Smillert #define optional_argument  2
4447f6c619Smillert 
4547f6c619Smillert struct option {
4647f6c619Smillert 	/* name of long option */
4747f6c619Smillert 	const char *name;
4847f6c619Smillert 	/*
4947f6c619Smillert 	 * one of no_argument, required_argument, and optional_argument:
5047f6c619Smillert 	 * whether option takes an argument
5147f6c619Smillert 	 */
5247f6c619Smillert 	int has_arg;
5347f6c619Smillert 	/* if not NULL, set *flag to val when option found */
5447f6c619Smillert 	int *flag;
5547f6c619Smillert 	/* if flag not NULL, value to set *flag to; else return value */
5647f6c619Smillert 	int val;
5747f6c619Smillert };
5847f6c619Smillert 
5947f6c619Smillert __BEGIN_DECLS
6047f6c619Smillert int	 getopt_long(int, char * const *, const char *,
6147f6c619Smillert 	    const struct option *, int *);
6247f6c619Smillert int	 getopt_long_only(int, char * const *, const char *,
6347f6c619Smillert 	    const struct option *, int *);
6447f6c619Smillert #ifndef _GETOPT_DEFINED_
6547f6c619Smillert #define _GETOPT_DEFINED_
6647f6c619Smillert int	 getopt(int, char * const *, const char *);
6747f6c619Smillert 
6847f6c619Smillert extern   char *optarg;                  /* getopt(3) external variables */
6947f6c619Smillert extern   int opterr;
7047f6c619Smillert extern   int optind;
7147f6c619Smillert extern   int optopt;
7247f6c619Smillert extern   int optreset;
7347f6c619Smillert #endif
7447f6c619Smillert __END_DECLS
7547f6c619Smillert 
7647f6c619Smillert #endif /* !_GETOPT_H_ */
77