summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/getopt.c131
-rw-r--r--openbsd-compat/getopt_long.c19
-rwxr-xr-xregress/modpipe.c2
5 files changed, 26 insertions, 134 deletions
diff --git a/ChangeLog b/ChangeLog
index 71c3ea61d..e0604abe1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,10 @@
5 getopt.c. Preprocessed source is identical other than line numbers. 5 getopt.c. Preprocessed source is identical other than line numbers.
6 - (dtucker) [openbsd-compat/getopt_long.c] Import from OpenBSD. No 6 - (dtucker) [openbsd-compat/getopt_long.c] Import from OpenBSD. No
7 portability changes yet. 7 portability changes yet.
8 - (dtucker) [openbsd-compat/Makefile.in openbsd-compat/getopt.c
9 openbsd-compat/getopt_long.c regress/modpipe.c] Remove getopt.c, add
10 portability code to getopt_long.c and switch over Makefile and the ugly
11 hack in modpipe.c. Fixes bz#1448.
8 12
920130423 1320130423
10 - (djm) [auth.c configure.ac misc.c monitor.c monitor_wrap.c] Support 14 - (djm) [auth.c configure.ac misc.c monitor.c monitor_wrap.c] Support
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index e1c3651e8..365cf006d 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.50 2013/02/15 01:13:02 dtucker Exp $ 1# $Id: Makefile.in,v 1.51 2013/05/10 06:28:56 dtucker Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -16,7 +16,7 @@ RANLIB=@RANLIB@
16INSTALL=@INSTALL@ 16INSTALL=@INSTALL@
17LDFLAGS=-L. @LDFLAGS@ 17LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o strtoull.o timingsafe_bcmp.o vis.o 19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt_long.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o strtoull.o timingsafe_bcmp.o vis.o
20 20
21COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-setres_id.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o 21COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-setres_id.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o
22 22
diff --git a/openbsd-compat/getopt.c b/openbsd-compat/getopt.c
deleted file mode 100644
index e5e80af06..000000000
--- a/openbsd-compat/getopt.c
+++ /dev/null
@@ -1,131 +0,0 @@
1/*
2 * Copyright (c) 1987, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/* OPENBSD ORIGINAL: lib/libc/stdlib/getopt.c */
31
32#include "includes.h"
33#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
34
35/* some defines to make it easier to keep the code in sync with upstream */
36/* #define getopt BSDgetopt is in defines.h */
37#define opterr BSDopterr
38#define optind BSDoptind
39#define optopt BSDoptopt
40#define optreset BSDoptreset
41#define optarg BSDoptarg
42
43#if defined(LIBC_SCCS) && !defined(lint)
44static char *rcsid = "$OpenBSD: getopt.c,v 1.5 2003/06/02 20:18:37 millert Exp $";
45#endif /* LIBC_SCCS and not lint */
46
47#include <stdio.h>
48#include <stdlib.h>
49#include <string.h>
50
51int opterr = 1, /* if error message should be printed */
52 optind = 1, /* index into parent argv vector */
53 optopt, /* character checked for validity */
54 optreset; /* reset getopt */
55char *optarg; /* argument associated with option */
56
57#define BADCH (int)'?'
58#define BADARG (int)':'
59#define EMSG ""
60
61/*
62 * getopt --
63 * Parse argc/argv argument vector.
64 */
65int
66getopt(nargc, nargv, ostr)
67 int nargc;
68 char * const *nargv;
69 const char *ostr;
70{
71 extern char *__progname;
72 static char *place = EMSG; /* option letter processing */
73 char *oli; /* option letter list index */
74
75 if (ostr == NULL)
76 return (-1);
77
78 if (optreset || !*place) { /* update scanning pointer */
79 optreset = 0;
80 if (optind >= nargc || *(place = nargv[optind]) != '-') {
81 place = EMSG;
82 return (-1);
83 }
84 if (place[1] && *++place == '-') { /* found "--" */
85 ++optind;
86 place = EMSG;
87 return (-1);
88 }
89 } /* option letter okay? */
90 if ((optopt = (int)*place++) == (int)':' ||
91 !(oli = strchr(ostr, optopt))) {
92 /*
93 * if the user didn't specify '-' as an option,
94 * assume it means -1.
95 */
96 if (optopt == (int)'-')
97 return (-1);
98 if (!*place)
99 ++optind;
100 if (opterr && *ostr != ':')
101 (void)fprintf(stderr,
102 "%s: illegal option -- %c\n", __progname, optopt);
103 return (BADCH);
104 }
105 if (*++oli != ':') { /* don't need argument */
106 optarg = NULL;
107 if (!*place)
108 ++optind;
109 }
110 else { /* need an argument */
111 if (*place) /* no white space */
112 optarg = place;
113 else if (nargc <= ++optind) { /* no arg */
114 place = EMSG;
115 if (*ostr == ':')
116 return (BADARG);
117 if (opterr)
118 (void)fprintf(stderr,
119 "%s: option requires an argument -- %c\n",
120 __progname, optopt);
121 return (BADCH);
122 }
123 else /* white space */
124 optarg = nargv[optind];
125 place = EMSG;
126 ++optind;
127 }
128 return (optopt); /* dump back option letter */
129}
130
131#endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */
diff --git a/openbsd-compat/getopt_long.c b/openbsd-compat/getopt_long.c
index e149fe0ac..6b36d0672 100644
--- a/openbsd-compat/getopt_long.c
+++ b/openbsd-compat/getopt_long.c
@@ -49,7 +49,22 @@
49 * POSSIBILITY OF SUCH DAMAGE. 49 * POSSIBILITY OF SUCH DAMAGE.
50 */ 50 */
51 51
52/* OPENBSD ORIGINAL: lib/libc/stdlib/getopt_long.c */
53#include "includes.h"
54
55#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
56#include "log.h"
57
58/*
59 * Some defines to make it easier to keep the code in sync with upstream.
60 * getopt opterr optind optopt optreset optarg are all in defines.h which is
61 * pulled in by includes.h.
62 */
63#define warnx logit
64
65#if 0
52#include <err.h> 66#include <err.h>
67#endif
53#include <errno.h> 68#include <errno.h>
54#include <getopt.h> 69#include <getopt.h>
55#include <stdlib.h> 70#include <stdlib.h>
@@ -484,6 +499,7 @@ getopt(int nargc, char * const *nargv, const char *options)
484 return (getopt_internal(nargc, nargv, options, NULL, NULL, 0)); 499 return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
485} 500}
486 501
502#if 0
487/* 503/*
488 * getopt_long -- 504 * getopt_long --
489 * Parse argc/argv argument vector. 505 * Parse argc/argv argument vector.
@@ -509,3 +525,6 @@ getopt_long_only(int nargc, char * const *nargv, const char *options,
509 return (getopt_internal(nargc, nargv, options, long_options, idx, 525 return (getopt_internal(nargc, nargv, options, long_options, idx,
510 FLAG_PERMUTE|FLAG_LONGONLY)); 526 FLAG_PERMUTE|FLAG_LONGONLY));
511} 527}
528#endif
529
530#endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */
diff --git a/regress/modpipe.c b/regress/modpipe.c
index 9629aa80b..3322d1a70 100755
--- a/regress/modpipe.c
+++ b/regress/modpipe.c
@@ -25,7 +25,7 @@
25#include <stdarg.h> 25#include <stdarg.h>
26#include <stdlib.h> 26#include <stdlib.h>
27#include <errno.h> 27#include <errno.h>
28#include "openbsd-compat/getopt.c" 28#include "openbsd-compat/getopt_long.c"
29 29
30static void err(int, const char *, ...) __attribute__((format(printf, 2, 3))); 30static void err(int, const char *, ...) __attribute__((format(printf, 2, 3)));
31static void errx(int, const char *, ...) __attribute__((format(printf, 2, 3))); 31static void errx(int, const char *, ...) __attribute__((format(printf, 2, 3)));