usage standard err(3) routine
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 27 Apr 1993 01:44:40 +0000 (17:44 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 27 Apr 1993 01:44:40 +0000 (17:44 -0800)
SCCS-vsn: usr.bin/mesg/mesg.c 5.4

usr/src/usr.bin/mesg/mesg.c

index 7697f58..a432b5e 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1987 Regents of the University of California.
+ * Copyright (c) 1987, 1993 Regents of the University of California.
  * All rights reserved.
  *
  * %sccs.include.redist.c%
  * All rights reserved.
  *
  * %sccs.include.redist.c%
@@ -7,26 +7,24 @@
 
 #ifndef lint
 char copyright[] =
 
 #ifndef lint
 char copyright[] =
-"@(#) Copyright (c) 1987 Regents of the University of California.\n\
+"@(#) Copyright (c) 1987, 1993 Regents of the University of California.\n\
  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)mesg.c     5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)mesg.c     5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include <err.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
-void err __P((const char *fmt, ...));
-void usage __P((void));
-
 int
 main(argc, argv)
        int argc;
 int
 main(argc, argv)
        int argc;
@@ -40,15 +38,15 @@ main(argc, argv)
                switch (ch) {
                case '?':
                default:
                switch (ch) {
                case '?':
                default:
-                       usage();
+                       goto usage;
                }
        argc -= optind;
        argv += optind;
 
        if ((tty = ttyname(STDERR_FILENO)) == NULL)
                }
        argc -= optind;
        argv += optind;
 
        if ((tty = ttyname(STDERR_FILENO)) == NULL)
-               err("ttyname: %s", strerror(errno));
+               err(1, "ttyname");
        if (stat(tty, &sb) < 0)
        if (stat(tty, &sb) < 0)
-               err("%s: %s", strerror(errno));
+               err(1, "%s", tty);
 
        if (*argv == NULL) {
                if (sb.st_mode & S_IWGRP) {
 
        if (*argv == NULL) {
                if (sb.st_mode & S_IWGRP) {
@@ -58,52 +56,18 @@ main(argc, argv)
                (void)fprintf(stderr, "is n\n");
                exit(1);
        }
                (void)fprintf(stderr, "is n\n");
                exit(1);
        }
+
        switch (*argv[0]) {
        case 'y':
                if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
        switch (*argv[0]) {
        case 'y':
                if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
-                       err("%s: %s", strerror(errno));
+                       err(1, "%s", tty);
                exit(0);
        case 'n':
                if (chmod(tty, sb.st_mode & ~S_IWGRP) < 0)
                exit(0);
        case 'n':
                if (chmod(tty, sb.st_mode & ~S_IWGRP) < 0)
-                       err("%s: %s", strerror(errno));
+                       err(1, "%s", tty);
                exit(1);
        }
                exit(1);
        }
-       usage();
-       /* NOTREACHED */
-}
 
 
-void
-usage()
-{
-       (void)fprintf(stderr, "usage: mesg [y | n]\n");
-       exit(2);
-}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(const char *fmt, ...)
-#else
-err(fmt, va_alist)
-       char *fmt;
-       va_dcl
-#endif
-{
-       va_list ap;
-#if __STDC__
-       va_start(ap, fmt);
-#else
-       va_start(ap);
-#endif
-       (void)fprintf(stderr, "mesg: ");
-       (void)vfprintf(stderr, fmt, ap);
-       va_end(ap);
-       (void)fprintf(stderr, "\n");
+usage: (void)fprintf(stderr, "usage: mesg [y | n]\n");
        exit(2);
        exit(2);
-       /* NOTREACHED */
 }
 }