Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/bin/sh/options.c,v rcsdiff: /ftp/cvs/cvsroot/src/bin/sh/options.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.52 retrieving revision 1.52.4.4 diff -u -p -r1.52 -r1.52.4.4 --- src/bin/sh/options.c 2017/11/21 03:42:39 1.52 +++ src/bin/sh/options.c 2020/04/21 19:37:34 1.52.4.4 @@ -1,4 +1,4 @@ -/* $NetBSD: options.c,v 1.52 2017/11/21 03:42:39 kre Exp $ */ +/* $NetBSD: options.c,v 1.52.4.4 2020/04/21 19:37:34 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: options.c,v 1.52 2017/11/21 03:42:39 kre Exp $"); +__RCSID("$NetBSD: options.c,v 1.52.4.4 2020/04/21 19:37:34 martin Exp $"); #endif #endif /* not lint */ @@ -60,6 +60,7 @@ __RCSID("$NetBSD: options.c,v 1.52 2017/ #include "memalloc.h" #include "error.h" #include "mystring.h" +#include "syntax.h" #ifndef SMALL #include "myhistedit.h" #endif @@ -456,7 +457,12 @@ setcmd(int argc, char **argv) void getoptsreset(const char *value) { - if (number(value) == 1) { + /* + * This is just to detect the case where OPTIND=1 + * is executed. Any other string assigned to OPTIND + * is OK, but is not a reset. No errors, so cannot use number() + */ + if (is_digit(*value) && strtol(value, NULL, 10) == 1) { shellparam.optnext = NULL; shellparam.reset = 1; } @@ -589,7 +595,11 @@ out: * Standard option processing (a la getopt) for builtin routines. The * only argument that is passed to nextopt is the option string; the * other arguments are unnecessary. It return the character, or '\0' on - * end of input. + * end of input. If optstring is NULL, then there are no options, and + * args are allowed to begin with '-', but a single leading "--" will be + * discarded. This is for some POSIX special builtins that require + * -- processing, have no args, and we never did opt processing before + * and need to retain backwards compat. */ int @@ -606,7 +616,11 @@ nextopt(const char *optstring) argptr++; if (p[0] == '-' && p[1] == '\0') /* check for "--" */ return '\0'; + if (optstring == NULL) /* not processing the "option" */ + argptr--; /* so make it be an arg again */ } + if (optstring == NULL) + return '\0'; c = *p++; for (q = optstring ; *q != c ; ) { if (*q == '\0')