Hi,

Todd C. Miller wrote on Wed, Oct 12, 2016 at 09:57:07AM -0600:
> On Wed, 12 Oct 2016 15:03:04 +0200, Ingo Schwarze wrote:
 
>> please just commit this patch you sent out back in July.
>> The old, verbose style keeps confusing people,
>> see for example Jan Stary's recent messages to tech@.
>> I guess you just overlooked my OK.
>> There was no opposition when you put this on tech@.

> Note that this changes the behavior slightly when an option is
> specified:
> 
> Before:
>     $ logname -z
>     logname: unknown option -- z
>     usage: logname
> 
> After:
>     $ logname -z
>     usage: logname
> 
> Depending on your point of view, this could be considered a feature.
> Personally, I prefer the getopt(3) way.

Oops, i missed that because i already had tedu's version in /usr/bin/
for several months.

So, here is a version of tedu@'s cleanup containing only the parts
that seem uncontroversial, even catering to joerg@'s remark that
somebody might add an option at some point - though i do hope it
doesn't come to that, 'cause id(1) already exists.

OK?
  Ingo


Index: logname.c
===================================================================
RCS file: /cvs/src/usr.bin/logname/logname.c,v
retrieving revision 1.9
diff -u -p -r1.9 logname.c
--- logname.c   9 Oct 2015 01:37:08 -0000       1.9
+++ logname.c   12 Oct 2016 17:48:26 -0000
@@ -30,13 +30,17 @@
  * SUCH DAMAGE.
  */
 
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <locale.h>
 #include <unistd.h>
-#include <err.h>
 
-void usage(void);
+static void __dead
+usage(void)
+{
+       (void)fprintf(stderr, "usage: logname\n");
+       exit(1);
+}
 
 int
 main(int argc, char *argv[])
@@ -44,33 +48,21 @@ main(int argc, char *argv[])
        int ch;
        char *p;
 
-       setlocale(LC_ALL, "");
-
        if (pledge("stdio", NULL) == -1)
                err(1, "pledge");
 
        while ((ch = getopt(argc, argv, "")) != -1)
                switch (ch) {
-               case '?':
                default:
                        usage();
-                       /* NOTREACHED */
                }
 
-       if (argc != optind) {
+       if (argc != optind)
                usage();
-               /* NOTREACHED */
-       }
 
        if ((p = getlogin()) == NULL)
                err(1, NULL);
-       (void)printf("%s\n", p);
-       exit(0);
-}
 
-void
-usage(void)
-{
-       (void)fprintf(stderr, "usage: logname\n");
-       exit(1);
+       (void)printf("%s\n", p);
+       return 0;
 }

Reply via email to