diff options
author | jilles <jilles@FreeBSD.org> | 2015-08-14 21:44:15 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2015-08-14 21:44:15 +0000 |
commit | 675e2bd4e494cf94a70c02819c58bfe21ede1817 (patch) | |
tree | ce023e8a5b63f9b11bbd886d1cae93de449f67b1 /bin/sh | |
parent | 5d6a758aba49ab5e7d273caca1f1844611a92771 (diff) | |
download | FreeBSD-src-675e2bd4e494cf94a70c02819c58bfe21ede1817.zip FreeBSD-src-675e2bd4e494cf94a70c02819c58bfe21ede1817.tar.gz |
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.
Diffstat (limited to 'bin/sh')
-rw-r--r-- | bin/sh/options.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/bin/sh/options.c b/bin/sh/options.c index 2d0ddce..1568937 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -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); |