Fix argument parsing in test(1) and chmod(1)
We just take the raw argument list as is. Using arg.h, arguments beginning with - would have been "eaten up". Writing a special "bailout" for arg.h was not a good option, not because it's not impossible (done in 6 LOC), but because it is a shoehorning around a corner case present for a few programs which are broken by design by POSIX.
This commit is contained in:
parent
ad6da18ca6
commit
3fa85f0f5e
4
chmod.c
4
chmod.c
|
@ -41,8 +41,8 @@ main(int argc, char *argv[])
|
||||||
struct recursor r = { .fn = chmodr, .hist = NULL, .depth = 0, .follow = 'P', .flags = 0};
|
struct recursor r = { .fn = chmodr, .hist = NULL, .depth = 0, .follow = 'P', .flags = 0};
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
argv0 = *(argv++);
|
argv0 = argv[0], argc--, argv++;
|
||||||
argc--;
|
|
||||||
for (; *argv && (*argv)[0] == '-'; argc--, argv++) {
|
for (; *argv && (*argv)[0] == '-'; argc--, argv++) {
|
||||||
if (!(*argv)[1])
|
if (!(*argv)[1])
|
||||||
usage();
|
usage();
|
||||||
|
|
1
chown.c
1
chown.c
|
@ -52,7 +52,6 @@ main(int argc, char *argv[])
|
||||||
struct recursor r = { .fn = chownpwgr, .hist = NULL, .depth = 0, .follow = 'P', .flags = 0};
|
struct recursor r = { .fn = chownpwgr, .hist = NULL, .depth = 0, .follow = 'P', .flags = 0};
|
||||||
char *owner, *group;
|
char *owner, *group;
|
||||||
|
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'h':
|
case 'h':
|
||||||
hflag = 1;
|
hflag = 1;
|
||||||
|
|
5
test.c
5
test.c
|
@ -148,10 +148,7 @@ main(int argc, char *argv[])
|
||||||
int (*narg[])(char *[]) = { noarg, onearg, twoarg, threearg, fourarg };
|
int (*narg[])(char *[]) = { noarg, onearg, twoarg, threearg, fourarg };
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
ARGBEGIN {
|
argv0 = argv[0], argc--, argv++;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
} ARGEND;
|
|
||||||
|
|
||||||
len = strlen(argv0);
|
len = strlen(argv0);
|
||||||
if (len && argv0[--len] == '[' && (!len || argv0[--len] == '/') && strcmp(argv[--argc], "]"))
|
if (len && argv0[--len] == '[' && (!len || argv0[--len] == '/') && strcmp(argv[--argc], "]"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user