1848b8605Smrg/* $OpenBSD: getopt.h,v 1.2 2008/06/26 05:42:04 ray Exp $ */ 2848b8605Smrg/* $NetBSD: getopt.h,v 1.1.1.1 2019/03/08 10:19:23 mrg Exp $ */ 3848b8605Smrg 4848b8605Smrg/*- 5848b8605Smrg * Copyright (c) 2000 The NetBSD Foundation, Inc. 6848b8605Smrg * All rights reserved. 7848b8605Smrg * 8848b8605Smrg * This code is derived from software contributed to The NetBSD Foundation 9848b8605Smrg * by Dieter Baron and Thomas Klausner. 10848b8605Smrg * 11848b8605Smrg * Redistribution and use in source and binary forms, with or without 12848b8605Smrg * modification, are permitted provided that the following conditions 13848b8605Smrg * are met: 14848b8605Smrg * 1. Redistributions of source code must retain the above copyright 15848b8605Smrg * notice, this list of conditions and the following disclaimer. 16848b8605Smrg * 2. Redistributions in binary form must reproduce the above copyright 17848b8605Smrg * notice, this list of conditions and the following disclaimer in the 18848b8605Smrg * documentation and/or other materials provided with the distribution. 19848b8605Smrg * 20848b8605Smrg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21848b8605Smrg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22848b8605Smrg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23848b8605Smrg * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24848b8605Smrg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25848b8605Smrg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26848b8605Smrg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27848b8605Smrg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28848b8605Smrg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29848b8605Smrg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30848b8605Smrg * POSSIBILITY OF SUCH DAMAGE. 31848b8605Smrg */ 32848b8605Smrg 33848b8605Smrg#ifndef _GETOPT_H_ 34848b8605Smrg#define _GETOPT_H_ 35848b8605Smrg 36848b8605Smrg/* 37848b8605Smrg * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions 38848b8605Smrg */ 39848b8605Smrg#define no_argument 0 40848b8605Smrg#define required_argument 1 41848b8605Smrg#define optional_argument 2 42848b8605Smrg 43848b8605Smrg#ifdef __cplusplus 44848b8605Smrgextern "C" { 45848b8605Smrg#endif 46848b8605Smrg 47848b8605Smrgstruct option { 48848b8605Smrg /* name of long option */ 49848b8605Smrg const char *name; 50848b8605Smrg /* 51848b8605Smrg * one of no_argument, required_argument, and optional_argument: 52848b8605Smrg * whether option takes an argument 53848b8605Smrg */ 54848b8605Smrg int has_arg; 55848b8605Smrg /* if not NULL, set *flag to val when option found */ 56848b8605Smrg int *flag; 57848b8605Smrg /* if flag not NULL, value to set *flag to; else return value */ 58848b8605Smrg int val; 59848b8605Smrg}; 60848b8605Smrg 61848b8605Smrgint getopt_long(int, char * const *, const char *, 62848b8605Smrg const struct option *, int *); 63848b8605Smrgint getopt_long_only(int, char * const *, const char *, 64848b8605Smrg const struct option *, int *); 65848b8605Smrg#ifndef _GETOPT_DEFINED_ 66848b8605Smrg#define _GETOPT_DEFINED_ 67848b8605Smrgint getopt(int, char * const *, const char *); 68848b8605Smrgint getsubopt(char **, char * const *, char **); 69848b8605Smrg 70848b8605Smrgextern char *optarg; /* getopt(3) external variables */ 71848b8605Smrgextern int opterr; 72848b8605Smrgextern int optind; 73848b8605Smrgextern int optopt; 74848b8605Smrgextern int optreset; 75848b8605Smrgextern char *suboptarg; /* getsubopt(3) external variable */ 76848b8605Smrg#endif 77848b8605Smrg 78848b8605Smrg#ifdef __cplusplus 79848b8605Smrg} 80848b8605Smrg#endif 81848b8605Smrg 82848b8605Smrg#endif /* !_GETOPT_H_ */ 83