mygetopt.h revision 284194
1145519Sdarrenr/* $NetBSD: getopt.h,v 1.8 2007/11/06 19:21:18 christos Exp $ */ 2145510Sdarrenr 3145510Sdarrenr/*- 4255332Scy * Copyright (c) 2000 The NetBSD Foundation, Inc. 5145510Sdarrenr * All rights reserved. 6145510Sdarrenr * 7145510Sdarrenr * This code is derived from software contributed to The NetBSD Foundation 8255332Scy * by Dieter Baron and Thomas Klausner. 9145510Sdarrenr * 10145510Sdarrenr * Redistribution and use in source and binary forms, with or without 11145510Sdarrenr * modification, are permitted provided that the following conditions 12145510Sdarrenr * are met: 13145510Sdarrenr * 1. Redistributions of source code must retain the above copyright 14145510Sdarrenr * notice, this list of conditions and the following disclaimer. 15145510Sdarrenr * 2. Redistributions in binary form must reproduce the above copyright 16145510Sdarrenr * notice, this list of conditions and the following disclaimer in the 17145510Sdarrenr * documentation and/or other materials provided with the distribution. 18145510Sdarrenr * 3. All advertising materials mentioning features or use of this software 19145510Sdarrenr * must display the following acknowledgement: 20145510Sdarrenr * This product includes software developed by the NetBSD 21145510Sdarrenr * Foundation, Inc. and its contributors. 22145510Sdarrenr * 4. Neither the name of The NetBSD Foundation nor the names of its 23145510Sdarrenr * contributors may be used to endorse or promote products derived 24145510Sdarrenr * from this software without specific prior written permission. 25145510Sdarrenr * 26145510Sdarrenr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27145510Sdarrenr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28255332Scy * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29145510Sdarrenr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30145510Sdarrenr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31145510Sdarrenr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32255332Scy * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33255332Scy * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34255332Scy * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35145510Sdarrenr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36145510Sdarrenr * POSSIBILITY OF SUCH DAMAGE. 37145510Sdarrenr */ 38145510Sdarrenr 39145510Sdarrenr#ifndef _GETOPT_H_ 40255332Scy#define _GETOPT_H_ 41145510Sdarrenr 42145510Sdarrenr#include <unistd.h> 43145510Sdarrenr 44145510Sdarrenr/* 45145510Sdarrenr * Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions 46145510Sdarrenr */ 47145510Sdarrenr#define no_argument 0 48255332Scy#define required_argument 1 49145510Sdarrenr#define optional_argument 2 50145510Sdarrenr 51145510Sdarrenrstruct option { 52145510Sdarrenr /* name of long option */ 53145510Sdarrenr const char *name; 54145510Sdarrenr /* 55145510Sdarrenr * one of no_argument, required_argument, and optional_argument: 56145510Sdarrenr * whether option takes an argument 57255332Scy */ 58145510Sdarrenr int has_arg; 59145510Sdarrenr /* if not NULL, set *flag to val when option found */ 60145510Sdarrenr int *flag; 61145510Sdarrenr /* if flag not NULL, value to set *flag to; else return value */ 62 int val; 63}; 64 65int getopt_long(int, char * const *, const char *, 66 const struct option *, int *); 67 68#endif /* !_GETOPT_H_ */ 69