1 /** $MirOS: src/include/getopt.h,v 1.3 2011/12/04 23:58:45 tg Exp $ */ 2 /* $OpenBSD: getopt.h,v 1.2 2008/06/26 05:42:04 ray Exp $ */ 3 /* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ 4 5 /*- 6 * Copyright (c) 2000 The NetBSD Foundation, Inc. 7 * All rights reserved. 8 * 9 * This code is derived from software contributed to The NetBSD Foundation 10 * by Dieter Baron and Thomas Klausner. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef _GETOPT_H_ 35 #define _GETOPT_H_ 36 37 #include <sys/cdefs.h> 38 #ifndef __MirBSD__ 39 #include <unistd.h> 40 #endif 41 42 /* 43 * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions 44 */ 45 #define no_argument 0 46 #define required_argument 1 47 #define optional_argument 2 48 49 struct option { 50 /* name of long option */ 51 const char *name; 52 /* 53 * one of no_argument, required_argument, and optional_argument: 54 * whether option takes an argument 55 */ 56 int has_arg; 57 /* if not NULL, set *flag to val when option found */ 58 int *flag; 59 /* if flag not NULL, value to set *flag to; else return value */ 60 int val; 61 }; 62 63 __BEGIN_DECLS 64 int getopt_long(int, char * const *, const char *, 65 const struct option *, int *); 66 int getopt_long_only(int, char * const *, const char *, 67 const struct option *, int *); 68 #ifndef _GETOPT_DEFINED_ 69 #define _GETOPT_DEFINED_ 70 int getopt(int, char * const *, const char *); 71 int getsubopt(char **, char * const *, char **); 72 73 extern char *optarg; /* getopt(3) external variables */ 74 extern int opterr; 75 extern int optind; 76 extern int optopt; 77 extern int optreset; 78 extern char *suboptarg; /* getsubopt(3) external variable */ 79 #endif 80 __END_DECLS 81 82 #endif /* !_GETOPT_H_ */ 83