/* $OpenBSD: getopt.h,v 1.2 2008/06/26 05:42:04 ray Exp $ */1/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */2/* $FreeBSD: head/include/getopt.h 203963 2010-02-16 19:28:10Z imp $ */34/*-5* SPDX-License-Identifier: BSD-2-Clause6*7* Copyright (c) 2000 The NetBSD Foundation, Inc.8* All rights reserved.9*10* This code is derived from software contributed to The NetBSD Foundation11* by Dieter Baron and Thomas Klausner.12*13* Redistribution and use in source and binary forms, with or without14* modification, are permitted provided that the following conditions15* are met:16* 1. Redistributions of source code must retain the above copyright17* notice, this list of conditions and the following disclaimer.18* 2. Redistributions in binary form must reproduce the above copyright19* notice, this list of conditions and the following disclaimer in the20* documentation and/or other materials provided with the distribution.21*22* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS23* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED24* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR25* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS26* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR27* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF28* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS29* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN30* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)31* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE32* POSSIBILITY OF SUCH DAMAGE.33*/3435#ifndef COMPAT_GETOPT_H36#define COMPAT_GETOPT_H3738/*39* GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension.40*/41#define no_argument 042#define required_argument 143#define optional_argument 24445struct option {46/* name of long option */47const char *name;48/*49* one of no_argument, required_argument, and optional_argument:50* whether option takes an argument51*/52int has_arg;53/* if not NULL, set *flag to val when option found */54int *flag;55/* if flag not NULL, value to set *flag to; else return value */56int val;57};5859sudo_dso_public int sudo_getopt_long(int, char * const *, const char *,60const struct option *, int *);61#undef getopt_long62#define getopt_long(_a, _b, _c, _d, _e) \63sudo_getopt_long((_a), (_b), (_c), (_d), (_e))6465sudo_dso_public int sudo_getopt_long_only(int, char * const *, const char *,66const struct option *, int *);67#undef getopt_long_only68#define getopt_long_only(_a, _b, _c, _d, _e) \69sudo_getopt_long_only((_a), (_b), (_c), (_d), (_e))70#if 071sudo_dso_public int sudo_getopt(int, char * const [], const char *);72#undef getopt73#define getopt(_a, _b, _c) sudo_getopt((_a), (_b), (_c))74#endif7576extern char *optarg; /* getopt(3) external variables */77extern int opterr;78extern int optind;79extern int optopt;80extern int optreset;8182#endif /* !COMPAT_GETOPT_H */838485