Add getopt.h and collect all the getopt related stuff here.

Make unistd.h include <getopt.h> to get the getopt stuff.
This adds support for getopt_long from Dieter Baron and Thomas Klausner.
This commit is contained in:
christos 2000-04-01 22:37:14 +00:00
parent f996345ebf
commit a91d8b9ec7
3 changed files with 95 additions and 20 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.83 2000/02/23 06:57:47 itojun Exp $
# $NetBSD: Makefile,v 1.84 2000/04/01 22:37:14 christos Exp $
# @(#)Makefile 8.2 (Berkeley) 1/4/94
SRCTOP= ..
@ -10,7 +10,7 @@ SRCTOP= ..
INCS= a.out.h ar.h assert.h bitstring.h bm.h cpio.h ctype.h db.h dirent.h \
disktab.h dlfcn.h err.h errno.h fmtmsg.h fnmatch.h fstab.h fts.h \
glob.h grp.h hesiod.h ieeefp.h ifaddrs.h \
getopt.h glob.h grp.h hesiod.h ieeefp.h ifaddrs.h \
iso646.h kvm.h langinfo.h libgen.h \
limits.h link.h link_aout.h link_elf.h locale.h \
login_cap.h malloc.h math.h md4.h \

90
include/getopt.h Normal file
View File

@ -0,0 +1,90 @@
/* $NetBSD: getopt.h,v 1.1 2000/04/01 22:37:15 christos Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Dieter Baron and Thomas Klausner.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GETOPT_H_
#define _GETOPT_H_
#include <sys/cdefs.h>
/*
* IEEE Std 1003.2-92, adopted in X/Open Portability Guide Issue 4 and later
*/
#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \
(_POSIX_C_SOURCE - 0) >= 2 || (_XOPEN_SOURCE - 0) >= 4
__BEGIN_DECLS
extern int opterr; /* if error messages should be printed */
extern int optind; /* index into parent argv vector */
extern int optopt; /* last invalid option letter */
extern char *optarg; /* argument associated with option */
int getopt __P((int, char * const *, const char *));
__END_DECLS
#endif
/*
* Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions
*/
#if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
#define no_argument 0
#define required_argument 1
#define optional_argument 2
struct option {
/* name of long option */
const char *name;
/*
* one of no_argument, required_argument, and optional_argument:
* whether option takes an argument
*/
int has_arg;
/* if not NULL, set *flag to val when option found */
int *flag;
/* if flag not NULL, value to set *flag to; else return value */
int val;
};
__BEGIN_DECLS
int getopt_long __P((int, char * const *, const char *,
const struct option *, int *));
extern int optreset; /* reset getopt */
extern char *suboptarg; /* getsubopt(3) external variable */
int getsubopt __P((char **, char * const *, char **));
__END_DECLS
#endif
#endif /* !_GETOPT_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: unistd.h,v 1.81 2000/01/27 05:33:07 itojun Exp $ */
/* $NetBSD: unistd.h,v 1.82 2000/04/01 22:37:15 christos Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@ -80,6 +80,8 @@
#include <sys/types.h>
#include <sys/unistd.h>
#include <getopt.h>
/*
* IEEE Std 1003.1-90
@ -144,20 +146,6 @@ int unlink __P((const char *));
ssize_t write __P((int, const void *, size_t));
/*
* IEEE Std 1003.2-92, adopted in X/Open Portability Guide Issue 4 and later
*/
#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \
(_POSIX_C_SOURCE - 0) >= 2 || (_XOPEN_SOURCE - 0) >= 4
int getopt __P((int, char * const [], const char *));
extern char *optarg; /* getopt(3) external variables */
extern int opterr;
extern int optind;
extern int optopt;
#endif
/*
* IEEE Std 1003.1b-93,
* also found in X/Open Portability Guide >= Issue 4 Verion 2
@ -298,7 +286,6 @@ int fchroot __P((int));
int getdomainname __P((char *, size_t));
int getgrouplist __P((const char *, gid_t, gid_t *, int *));
mode_t getmode __P((const void *, mode_t));
int getsubopt __P((char **, char * const *, char **));
__aconst char *getusershell __P((void));
int initgroups __P((const char *, gid_t));
int iruserok __P((u_int32_t, int, const char *, const char *));
@ -338,8 +325,6 @@ int iruserok_sa __P((const void *, int, int, const char *, const char *));
#endif
extern __const char *__const *sys_siglist __RENAME(__sys_siglist14);
extern int optreset; /* getopt(3) external variable */
extern char *suboptarg; /* getsubopt(3) external variable */
#endif
__END_DECLS