Re: logname turd polish
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 - 1.9 +++ logname.c 12 Oct 2016 17:48:26 - @@ -30,13 +30,17 @@ * SUCH DAMAGE. */ +#include #include #include -#include #include -#include -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; }
Re: PING: Re: logname turd polish
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. - todd
PING: Re: logname turd polish
Hi Ted, 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@. Yours, Ingo Ingo Schwarze wrote on Fri, Jul 01, 2016 at 11:40:01PM +0200: > Ted Unangst wrote on Thu, Jun 23, 2016 at 09:06:10PM -0400: >> just because. > OK schwarze@ > 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 - 1.9 +++ logname.c 24 Jun 2016 01:02:58 - @@ -32,45 +32,30 @@ #include #include -#include +#include #include #include -void usage(void); +static void __dead +usage(void) +{ + (void)fprintf(stderr, "usage: logname\n"); + exit(1); +} int main(int argc, char *argv[]) { - int ch; - char *p; - - setlocale(LC_ALL, ""); + const char *p; 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 == 1 || (argc == 2 && strcmp(argv[1], "--") == 0))) 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); + return 0; }