Re: arch(1): small cleanup

2015-09-24 Thread Ted Unangst
Michael Reed wrote:
> Hi all,
> 
> I test it out as both `arch' and `machine' and didn't observe
> any differences.  Also, I figured I might as well convert exit(3)
> to return while touching this code, as was done in [1].

this is cleaner i think.


Index: arch.c
===
RCS file: /cvs/src/usr.bin/arch/arch.c,v
retrieving revision 1.14
diff -u -p -r1.14 arch.c
--- arch.c  8 Feb 2015 23:40:34 -   1.14
+++ arch.c  24 Sep 2015 15:00:43 -
@@ -32,7 +32,7 @@
 #include 
 #include 
 
-static void usage(void);
+static void __dead usage(void);
 
 static int machine;
 
@@ -54,7 +54,7 @@ main(int argc, char *argv[])
arch = MACHINE_ARCH;
opts = "ks";
}
-   while ((c = getopt(argc, argv, opts)) != -1)
+   while ((c = getopt(argc, argv, opts)) != -1) {
switch (c) {
case 'a':
arch = MACHINE_ARCH;
@@ -67,22 +67,16 @@ main(int argc, char *argv[])
break;
default:
usage();
-   /* NOTREACHED */
}
-   if (optind != argc) {
-   usage();
-   /* NOTREACHED */
-   }
-   if (!short_form) {
-   fputs("OpenBSD", stdout);
-   fputc('.', stdout);
}
-   fputs(arch, stdout);
-   fputc('\n', stdout);
-   exit(0);
+   if (optind != argc)
+   usage();
+
+   printf("%s%s\n", short_form ? "" : "OpenBSD.", arch);
+   return (0);
 }
 
-static void
+static void __dead
 usage(void)
 {
if (machine)



arch(1): small cleanup

2015-09-23 Thread Michael Reed
Hi all,

I test it out as both `arch' and `machine' and didn't observe
any differences.  Also, I figured I might as well convert exit(3)
to return while touching this code, as was done in [1].

Regard,
Michael

[1]: https://marc.info/?l=openbsd-tech=144095769912804=2



Index: src/usr.bin/arch/arch.c
===
RCS file: /cvs/src/usr.bin/arch/arch.c,v
retrieving revision 1.14
diff -u -p -r1.14 arch.c
--- src/usr.bin/arch/arch.c 8 Feb 2015 23:40:34 -   1.14
+++ src/usr.bin/arch/arch.c 23 Sep 2015 20:09:18 -
@@ -25,7 +25,6 @@
 
 #include  /* MACHINE MACHINE_ARCH */
 
-#include 
 #include 
 #include 
 #include 
@@ -73,13 +72,10 @@ main(int argc, char *argv[])
usage();
/* NOTREACHED */
}
-   if (!short_form) {
-   fputs("OpenBSD", stdout);
-   fputc('.', stdout);
-   }
-   fputs(arch, stdout);
-   fputc('\n', stdout);
-   exit(0);
+   if (!short_form)
+   fputs("OpenBSD.", stdout);
+   puts(arch);
+   return 0;
 }
 
 static void