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

(patch) some cleanup in wall(1)



Changes the following:
- extend error messages and save few bytes with replace errx(3) -> err(3)
  use err(3) is more correct here, since fstat(2), fopen(3) etc set errno
  on failure
- add missed __dead
- minor knf

Index: usr.bin/wall/wall.c
===================================================================
RCS file: /cvs/src/usr.bin/wall/wall.c,v
retrieving revision 1.17
diff -u -r1.17 wall.c
--- usr.bin/wall/wall.c	2001/11/05 13:11:07	1.17
+++ usr.bin/wall/wall.c	2003/03/10 21:03:53
@@ -57,16 +57,16 @@
 #include <sys/time.h>
 #include <sys/uio.h>
 
+#include <err.h>
+#include <grp.h>
 #include <paths.h>
 #include <pwd.h>
-#include <grp.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <utmp.h>
 #include <vis.h>
-#include <err.h>
 
 struct wallgroup {
 	gid_t	gid;
@@ -123,8 +123,8 @@
 
 	makemsg(*argv);
 
-	if (!(fp = fopen(_PATH_UTMP, "r")))
-		errx(1, "cannot read %s.", _PATH_UTMP);
+	if ((fp = fopen(_PATH_UTMP, "r")) == NULL)
+		err(1, "cannot read %s", _PATH_UTMP);
 	iov.iov_base = mbuf;
 	iov.iov_len = mbufsize;
 	/* NOSTRICT */
@@ -176,7 +176,7 @@
 		fp = fdopen(fd, "r+");
 	}
 	if (fd == -1 || fp == NULL)
-		errx(1, "can't open temporary file.");
+		err(1, "cannot open temporary file");
 
 	if (!nobanner) {
 		if (!(whom = getlogin()))
@@ -210,7 +210,7 @@
 
 		setegid(getgid());
 		if (freopen(fname, "r", stdin) == NULL)
-			errx(1, "can't read %s.", fname);
+			err(1, "cannot read %s", fname);
 		setegid(egid);
 	}
 	while (fgets(lbuf, sizeof(lbuf), stdin))
@@ -234,12 +234,12 @@
 	rewind(fp);
 
 	if (fstat(fd, &sbuf))
-		errx(1, "can't stat temporary file.");
+		err(1, "cannot stat temporary file");
 	mbufsize = sbuf.st_size;
-	if (!(mbuf = malloc((u_int)mbufsize)))
-		errx(1, "out of memory.");
+	if ((mbuf = malloc((u_int)mbufsize)) == NULL)
+		err(1, "malloc");
 	if (fread(mbuf, sizeof(*mbuf), mbufsize, fp) != mbufsize)
-		errx(1, "can't read temporary file.");
+		err(1, "cannot read temporary file");
 	(void)close(fd);
 }
 
@@ -254,23 +254,23 @@
 
 	g = (struct wallgroup *)malloc(sizeof *g);
 	if (g == NULL)
-		errx(1, "out of memory.");
+		err(1, "malloc");
 	g->gid = grp->gr_gid;
 	g->name = name;
 	g->mem = (char **)malloc(i + 1);
 	if (g->mem == NULL)
-		errx(1, "out of memory.");
+		err(1, "malloc");
 	for (i = 0; grp->gr_mem[i] != NULL; i++) {
 		g->mem[i] = strdup(grp->gr_mem[i]);
 		if (g->mem[i] == NULL)
-			errx(1, "out of memory.");
+			err(1, "strdup");
 	}
 	g->mem[i] = NULL;
 	g->next = grouplist;
 	grouplist = g;
 }
 
-void
+__dead void
 usage(void)
 {
 	extern char *__progname;



Visit your host, monkey.org