mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-29 16:54:51 +02:00
- (dtucker) [openbsd-compat/getopt.c] Factor out portibility changes to
getopt.c. Preprocessed source is identical other than line numbers.
This commit is contained in:
parent
abbc7a7c02
commit
35b2fe99be
@ -1,6 +1,8 @@
|
|||||||
20130510
|
20130510
|
||||||
- (dtucker) [configure.ac] Enable -Wsizeof-pointer-memaccess if the compiler
|
- (dtucker) [configure.ac] Enable -Wsizeof-pointer-memaccess if the compiler
|
||||||
supports it. Mentioned by Colin Watson in bz#2100, ok djm.
|
supports it. Mentioned by Colin Watson in bz#2100, ok djm.
|
||||||
|
- (dtucker) [openbsd-compat/getopt.c] Factor out portibility changes to
|
||||||
|
getopt.c. Preprocessed source is identical other than line numbers.
|
||||||
|
|
||||||
20130423
|
20130423
|
||||||
- (djm) [auth.c configure.ac misc.c monitor.c monitor_wrap.c] Support
|
- (djm) [auth.c configure.ac misc.c monitor.c monitor_wrap.c] Support
|
||||||
|
@ -32,6 +32,14 @@
|
|||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
|
#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
|
||||||
|
|
||||||
|
/* some defines to make it easier to keep the code in sync with upstream */
|
||||||
|
/* #define getopt BSDgetopt is in defines.h */
|
||||||
|
#define opterr BSDopterr
|
||||||
|
#define optind BSDoptind
|
||||||
|
#define optopt BSDoptopt
|
||||||
|
#define optreset BSDoptreset
|
||||||
|
#define optarg BSDoptarg
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
static char *rcsid = "$OpenBSD: getopt.c,v 1.5 2003/06/02 20:18:37 millert Exp $";
|
static char *rcsid = "$OpenBSD: getopt.c,v 1.5 2003/06/02 20:18:37 millert Exp $";
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
@ -40,11 +48,11 @@ static char *rcsid = "$OpenBSD: getopt.c,v 1.5 2003/06/02 20:18:37 millert Exp $
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int BSDopterr = 1, /* if error message should be printed */
|
int opterr = 1, /* if error message should be printed */
|
||||||
BSDoptind = 1, /* index into parent argv vector */
|
optind = 1, /* index into parent argv vector */
|
||||||
BSDoptopt, /* character checked for validity */
|
optopt, /* character checked for validity */
|
||||||
BSDoptreset; /* reset getopt */
|
optreset; /* reset getopt */
|
||||||
char *BSDoptarg; /* argument associated with option */
|
char *optarg; /* argument associated with option */
|
||||||
|
|
||||||
#define BADCH (int)'?'
|
#define BADCH (int)'?'
|
||||||
#define BADARG (int)':'
|
#define BADARG (int)':'
|
||||||
@ -55,7 +63,7 @@ char *BSDoptarg; /* argument associated with option */
|
|||||||
* Parse argc/argv argument vector.
|
* Parse argc/argv argument vector.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
BSDgetopt(nargc, nargv, ostr)
|
getopt(nargc, nargv, ostr)
|
||||||
int nargc;
|
int nargc;
|
||||||
char * const *nargv;
|
char * const *nargv;
|
||||||
const char *ostr;
|
const char *ostr;
|
||||||
@ -67,57 +75,57 @@ BSDgetopt(nargc, nargv, ostr)
|
|||||||
if (ostr == NULL)
|
if (ostr == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (BSDoptreset || !*place) { /* update scanning pointer */
|
if (optreset || !*place) { /* update scanning pointer */
|
||||||
BSDoptreset = 0;
|
optreset = 0;
|
||||||
if (BSDoptind >= nargc || *(place = nargv[BSDoptind]) != '-') {
|
if (optind >= nargc || *(place = nargv[optind]) != '-') {
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (place[1] && *++place == '-') { /* found "--" */
|
if (place[1] && *++place == '-') { /* found "--" */
|
||||||
++BSDoptind;
|
++optind;
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
} /* option letter okay? */
|
} /* option letter okay? */
|
||||||
if ((BSDoptopt = (int)*place++) == (int)':' ||
|
if ((optopt = (int)*place++) == (int)':' ||
|
||||||
!(oli = strchr(ostr, BSDoptopt))) {
|
!(oli = strchr(ostr, optopt))) {
|
||||||
/*
|
/*
|
||||||
* if the user didn't specify '-' as an option,
|
* if the user didn't specify '-' as an option,
|
||||||
* assume it means -1.
|
* assume it means -1.
|
||||||
*/
|
*/
|
||||||
if (BSDoptopt == (int)'-')
|
if (optopt == (int)'-')
|
||||||
return (-1);
|
return (-1);
|
||||||
if (!*place)
|
if (!*place)
|
||||||
++BSDoptind;
|
++optind;
|
||||||
if (BSDopterr && *ostr != ':')
|
if (opterr && *ostr != ':')
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"%s: illegal option -- %c\n", __progname, BSDoptopt);
|
"%s: illegal option -- %c\n", __progname, optopt);
|
||||||
return (BADCH);
|
return (BADCH);
|
||||||
}
|
}
|
||||||
if (*++oli != ':') { /* don't need argument */
|
if (*++oli != ':') { /* don't need argument */
|
||||||
BSDoptarg = NULL;
|
optarg = NULL;
|
||||||
if (!*place)
|
if (!*place)
|
||||||
++BSDoptind;
|
++optind;
|
||||||
}
|
}
|
||||||
else { /* need an argument */
|
else { /* need an argument */
|
||||||
if (*place) /* no white space */
|
if (*place) /* no white space */
|
||||||
BSDoptarg = place;
|
optarg = place;
|
||||||
else if (nargc <= ++BSDoptind) { /* no arg */
|
else if (nargc <= ++optind) { /* no arg */
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
if (*ostr == ':')
|
if (*ostr == ':')
|
||||||
return (BADARG);
|
return (BADARG);
|
||||||
if (BSDopterr)
|
if (opterr)
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"%s: option requires an argument -- %c\n",
|
"%s: option requires an argument -- %c\n",
|
||||||
__progname, BSDoptopt);
|
__progname, optopt);
|
||||||
return (BADCH);
|
return (BADCH);
|
||||||
}
|
}
|
||||||
else /* white space */
|
else /* white space */
|
||||||
BSDoptarg = nargv[BSDoptind];
|
optarg = nargv[optind];
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
++BSDoptind;
|
++optind;
|
||||||
}
|
}
|
||||||
return (BSDoptopt); /* dump back option letter */
|
return (optopt); /* dump back option letter */
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */
|
#endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user