[hackers] [sbase] Do not use arg.h for tools which take no flags || FRIGN

From: <git_AT_suckless.org>
Date: Sat, 25 Apr 2015 12:43:20 +0200 (CEST)

commit 9016d288f1cd03bf514fe84d537b203040e1ccf8
Author: FRIGN <dev_AT_frign.de>
Date: Fri Apr 24 23:54:17 2015 +0200

    Do not use arg.h for tools which take no flags
    
    We've already seen the issue with echo(1): Before we changed it to
    ignore "--", the command
    
    $ echo --
    
    did not work as expected. Given POSIX mandated this and makes most
    sense, in the interest of consistency the other tools need to be
    streamlined for that as well.
    Looking at yes(1) for instance, there's no reason to skip "--" in
    the argument list.
    We do not have long options like GNU does and there's no reason to
    tinker with that here.
    
    The majority of tools changed are ones taking lists of arguments
    or only a single one. There's no reason why dirname should "fail"
    on "--". In the end, this is a valid name.
    
    The practice of hand-holding the user was established with the GNU
    coreutils. "--help" and "--version" long-options are a disgrace to
    what could've been done properly with manpages.

diff --git a/basename.c b/basename.c
index bb5eaa4..4a6ac2a 100644
--- a/basename.c
+++ b/basename.c
_AT_@ -17,10 +17,7 @@ main(int argc, char *argv[])
         ssize_t off;
         char *p;
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (argc != 1 && argc != 2)
                 usage();
diff --git a/chroot.c b/chroot.c
index beec628..0b797cc 100644
--- a/chroot.c
+++ b/chroot.c
_AT_@ -17,10 +17,7 @@ main(int argc, char *argv[])
         char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *cmd;
         int savederrno;
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (!argc)
                 usage();
diff --git a/cksum.c b/cksum.c
index b2a95b4..581af7a 100644
--- a/cksum.c
+++ b/cksum.c
_AT_@ -84,22 +84,13 @@ cksum(FILE *fp, const char *s)
         putchar('\n');
 }
 
-static void
-usage(void)
-{
- eprintf("usage: %s [file ...]\n", argv0);
-}
-
 int
 main(int argc, char *argv[])
 {
         FILE *fp;
         int ret = 0;
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (!argc) {
                 cksum(stdin, NULL);
diff --git a/dirname.c b/dirname.c
index 4542199..4bef9a4 100644
--- a/dirname.c
+++ b/dirname.c
_AT_@ -13,10 +13,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (argc != 1)
                 usage();
diff --git a/echo.c b/echo.c
index 1906133..23bc55f 100644
--- a/echo.c
+++ b/echo.c
_AT_@ -8,7 +8,9 @@ main(int argc, char *argv[])
 {
         int nflag = 0;
 
- if (*++argv && !strcmp(*argv, "-n")) {
+ argv0 = argv[0], argc--, argv++;
+
+ if (*argv && !strcmp(*argv, "-n")) {
                 nflag = 1;
                 argc--, argv++;
         }
diff --git a/hostname.c b/hostname.c
index dff32af..a0e3969 100644
--- a/hostname.c
+++ b/hostname.c
_AT_@ -16,10 +16,7 @@ main(int argc, char *argv[])
 {
         char host[HOST_NAME_MAX + 1];
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (!argc) {
                 if (gethostname(host, sizeof(host)) < 0)
diff --git a/link.c b/link.c
index 6af7544..e169f0a 100644
--- a/link.c
+++ b/link.c
_AT_@ -12,10 +12,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (argc != 2)
                 usage();
diff --git a/nohup.c b/nohup.c
index 59970cb..080b210 100644
--- a/nohup.c
+++ b/nohup.c
_AT_@ -19,10 +19,7 @@ main(int argc, char *argv[])
 {
         int fd, savederrno;
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (!argc)
                 usage();
diff --git a/printenv.c b/printenv.c
index f88e4d2..2c1e711 100644
--- a/printenv.c
+++ b/printenv.c
_AT_@ -6,22 +6,13 @@
 
 extern char **environ;
 
-static void
-usage(void)
-{
- eprintf("usage: %s [var ...]\n", argv0);
-}
-
 int
 main(int argc, char *argv[])
 {
         char *var;
         int ret = 0;
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (!argc) {
                 for (; *environ; environ++)
diff --git a/setsid.c b/setsid.c
index 98acaae..4c885a4 100644
--- a/setsid.c
+++ b/setsid.c
_AT_@ -15,10 +15,7 @@ main(int argc, char *argv[])
 {
         int savederrno;
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (!argc)
                 usage();
diff --git a/sleep.c b/sleep.c
index ce20858..b1028ed 100644
--- a/sleep.c
+++ b/sleep.c
_AT_@ -14,10 +14,7 @@ main(int argc, char *argv[])
 {
         unsigned seconds;
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (argc != 1)
                 usage();
diff --git a/sponge.c b/sponge.c
index ee1d338..a2861a0 100644
--- a/sponge.c
+++ b/sponge.c
_AT_@ -15,10 +15,7 @@ main(int argc, char *argv[])
 {
         FILE *fp, *tmpfp;
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (argc != 1)
                 usage();
diff --git a/sync.c b/sync.c
index 5d92233..15e53f4 100644
--- a/sync.c
+++ b/sync.c
_AT_@ -12,10 +12,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (argc)
                 usage();
diff --git a/tty.c b/tty.c
index 6b580d3..5afec79 100644
--- a/tty.c
+++ b/tty.c
_AT_@ -15,10 +15,7 @@ main(int argc, char *argv[])
 {
         char *tty;
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (argc)
                 usage();
diff --git a/unlink.c b/unlink.c
index 797d18a..bdc6061 100644
--- a/unlink.c
+++ b/unlink.c
_AT_@ -12,10 +12,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         if (argc != 1)
                 usage();
diff --git a/yes.c b/yes.c
index 000f367..cbd81dc 100644
--- a/yes.c
+++ b/yes.c
_AT_@ -3,21 +3,12 @@
 
 #include "util.h"
 
-static void
-usage(void)
-{
- eprintf("usage: %s [string ...]\n", argv0);
-}
-
 int
 main(int argc, char *argv[])
 {
         char **p;
 
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
+ argv0 = argv[0], argc--, argv++;
 
         for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) {
                 fputs(*p ? *p : "y", stdout);
Received on Sat Apr 25 2015 - 12:43:20 CEST

This archive was generated by hypermail 2.3.0 : Sat Apr 25 2015 - 12:48:14 CEST