sh: When setting option via long name, don't go via letter.
Looking up the letter makes no sense and prevents adding options that only have a long name, no letter.
This commit is contained in:
parent
5d6a758aba
commit
675e2bd4e4
@ -73,6 +73,7 @@ char *minusc; /* argument to -c option */
|
||||
static void options(int);
|
||||
static void minus_o(char *, int);
|
||||
static void setoption(int, int);
|
||||
static void setoptionbyindex(int, int);
|
||||
static int getopts(char *, char *, char **, char ***, char **);
|
||||
|
||||
|
||||
@ -269,7 +270,7 @@ minus_o(char *name, int val)
|
||||
} else {
|
||||
for (i = 0; i < NOPTS; i++)
|
||||
if (equal(name, optlist[i].name)) {
|
||||
setoption(optlist[i].letter, val);
|
||||
setoptionbyindex(i, val);
|
||||
return;
|
||||
}
|
||||
error("Illegal option -o %s", name);
|
||||
@ -278,26 +279,32 @@ minus_o(char *name, int val)
|
||||
|
||||
|
||||
static void
|
||||
setoption(int flag, int val)
|
||||
setoptionbyindex(int idx, int val)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (flag == 'p' && !val && privileged) {
|
||||
if (optlist[idx].letter == 'p' && !val && privileged) {
|
||||
if (setgid(getgid()) == -1)
|
||||
error("setgid");
|
||||
if (setuid(getuid()) == -1)
|
||||
error("setuid");
|
||||
}
|
||||
optlist[idx].val = val;
|
||||
if (val) {
|
||||
/* #%$ hack for ksh semantics */
|
||||
if (optlist[idx].letter == 'V')
|
||||
Eflag = 0;
|
||||
else if (optlist[idx].letter == 'E')
|
||||
Vflag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
setoption(int flag, int val)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NOPTS; i++)
|
||||
if (optlist[i].letter == flag) {
|
||||
optlist[i].val = val;
|
||||
if (val) {
|
||||
/* #%$ hack for ksh semantics */
|
||||
if (flag == 'V')
|
||||
Eflag = 0;
|
||||
else if (flag == 'E')
|
||||
Vflag = 0;
|
||||
}
|
||||
setoptionbyindex(i, val);
|
||||
return;
|
||||
}
|
||||
error("Illegal option -%c", flag);
|
||||
|
Loading…
Reference in New Issue
Block a user