[hackers] [sbase] Fix argument parsing in test(1) and chmod(1) || FRIGN

From: <git_AT_suckless.org>
Date: Sat, 14 Mar 2015 00:23:32 +0100 (CET)

commit b2a05d4e22f521b9e04475ebb9e6b3674104590d
Author: FRIGN <dev_AT_frign.de>
Date: Fri Mar 13 23:43:13 2015 +0100

    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.

diff --git a/chmod.c b/chmod.c
index f93fc16..1cfa6b3 100644
--- a/chmod.c
+++ b/chmod.c
_AT_@ -41,8 +41,8 @@ main(int argc, char *argv[])
         struct recursor r = { .fn = chmodr, .hist = NULL, .depth = 0, .follow = 'P', .flags = 0};
         size_t i;
 
- argv0 = *(argv++);
- argc--;
+ argv0 = argv[0], argc--, argv++;
+
         for (; *argv && (*argv)[0] == '-'; argc--, argv++) {
                 if (!(*argv)[1])
                         usage();
diff --git a/chown.c b/chown.c
index 290ac11..bc2bb1f 100644
--- a/chown.c
+++ b/chown.c
_AT_@ -52,7 +52,6 @@ main(int argc, char *argv[])
         struct recursor r = { .fn = chownpwgr, .hist = NULL, .depth = 0, .follow = 'P', .flags = 0};
         char *owner, *group;
 
-
         ARGBEGIN {
         case 'h':
                 hflag = 1;
diff --git a/test.c b/test.c
index b9d4834..52e2275 100644
--- a/test.c
+++ b/test.c
_AT_@ -148,10 +148,7 @@ main(int argc, char *argv[])
         int (*narg[])(char *[]) = { noarg, onearg, twoarg, threearg, fourarg };
         size_t len;
 
- ARGBEGIN {
- default:
- break;
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         len = strlen(argv0);
         if (len && argv0[--len] == '[' && (!len || argv0[--len] == '/') && strcmp(argv[--argc], "]"))
Received on Sat Mar 14 2015 - 00:23:32 CET

This archive was generated by hypermail 2.3.0 : Sat Mar 14 2015 - 00:24:10 CET