Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/mesg - Check stdin, stdout, and stderr for a tty. Fr...



details:   https://anonhg.NetBSD.org/src/rev/5ce4a52029fa
branches:  trunk
changeset: 583327:5ce4a52029fa
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jul 30 16:14:39 2005 +0000

description:
- Check stdin, stdout, and stderr for a tty. From Liam Foy for SUSv3
  compliance.
- While here, delint, prototypes, getsetprogname, warns=3

diffstat:

 usr.bin/mesg/Makefile |   3 ++-
 usr.bin/mesg/mesg.c   |  34 +++++++++++++++++-----------------
 2 files changed, 19 insertions(+), 18 deletions(-)

diffs (95 lines):

diff -r 4e4df37897a7 -r 5ce4a52029fa usr.bin/mesg/Makefile
--- a/usr.bin/mesg/Makefile     Sat Jul 30 15:21:20 2005 +0000
+++ b/usr.bin/mesg/Makefile     Sat Jul 30 16:14:39 2005 +0000
@@ -1,6 +1,7 @@
-#      $NetBSD: Makefile,v 1.5 1997/10/19 04:23:04 lukem Exp $
+#      $NetBSD: Makefile,v 1.6 2005/07/30 16:14:39 christos Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 
+WARNS=3
 PROG=  mesg
 
 .include <bsd.prog.mk>
diff -r 4e4df37897a7 -r 5ce4a52029fa usr.bin/mesg/mesg.c
--- a/usr.bin/mesg/mesg.c       Sat Jul 30 15:21:20 2005 +0000
+++ b/usr.bin/mesg/mesg.c       Sat Jul 30 16:14:39 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mesg.c,v 1.6 2003/08/07 11:15:12 agc Exp $     */
+/*     $NetBSD: mesg.c,v 1.7 2005/07/30 16:14:39 christos Exp $        */
 
 /*
  * Copyright (c) 1987, 1993
@@ -45,7 +45,7 @@
 #if 0
 static char sccsid[] = "@(#)mesg.c     8.2 (Berkeley) 1/21/94";
 #endif
-__RCSID("$NetBSD: mesg.c,v 1.6 2003/08/07 11:15:12 agc Exp $");
+__RCSID("$NetBSD: mesg.c,v 1.7 2005/07/30 16:14:39 christos Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -58,17 +58,15 @@
 #include <string.h>
 #include <unistd.h>
 
-int    main __P((int, char **));
-
 int
-main(argc, argv)
-       int argc;
-       char *argv[];
+main(int argc, char *argv[])
 {
        struct stat sb;
        char *tty;
        int ch;
 
+       setprogname(*argv);
+
        while ((ch = getopt(argc, argv, "")) != -1)
                switch (ch) {
                case '?':
@@ -78,31 +76,33 @@
        argc -= optind;
        argv += optind;
 
-       if ((tty = ttyname(STDERR_FILENO)) == NULL)
+       if ((tty = ttyname(STDIN_FILENO)) == NULL &&
+           (tty = ttyname(STDOUT_FILENO)) == NULL &&
+           (tty = ttyname(STDERR_FILENO)) == NULL)
                err(2, "ttyname");
-       if (stat(tty, &sb) < 0)
+       if (stat(tty, &sb) == -1)
                err(2, "%s", tty);
 
        if (*argv == NULL) {
                if (sb.st_mode & S_IWGRP) {
                        (void)fprintf(stderr, "is y\n");
-                       exit(0);
+                       return 0;
                }
                (void)fprintf(stderr, "is n\n");
-               exit(1);
+               return 1;
        }
 
        switch (*argv[0]) {
        case 'y':
-               if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
+               if (chmod(tty, sb.st_mode | S_IWGRP) == -1)
                        err(2, "%s", tty);
-               exit(0);
+               return 0;
        case 'n':
-               if (chmod(tty, sb.st_mode & ~S_IWGRP) < 0)
+               if (chmod(tty, sb.st_mode & ~S_IWGRP) == -1)
                        err(2, "%s", tty);
-               exit(1);
+               return 1;
        }
 
-usage: (void)fprintf(stderr, "usage: mesg [y | n]\n");
-       exit(2);
+usage: (void)fprintf(stderr, "Usage: %s [y | n]\n", getprogname());
+       return 2;
 }



Home | Main Index | Thread Index | Old Index