- Remove unneeded (void) casts
- Replace sysctl calls with sysctlbyname


Index: pr_time.c
===================================================================
RCS file: /cvs/src/usr.bin/w/pr_time.c,v
retrieving revision 1.3
diff -u -u -r1.3 pr_time.c
--- pr_time.c	4 Oct 2003 20:36:54 -0000	1.3
+++ pr_time.c	29 Oct 2004 16:16:39 -0000
@@ -61,7 +61,7 @@
 
 	/* If more than a week, use day-month-year. */
 	if (diff > 86400 * 7)
-		(void)strcpy(fmt, "%d%b%y");
+		strcpy(fmt, "%d%b%y");
 
 	/* If not today, use day-hour-am/pm. */
 	else if (tm.tm_mday != tp.tm_mday ||
@@ -69,16 +69,16 @@
 		 tm.tm_year != tp.tm_year) {
 	/* The line below does not take DST into consideration */
 	/* else if (*now / 86400 != *started / 86400) { */
-		(void)strcpy(fmt, use_ampm ? "%a%I%p" : "%a%H");
+		strcpy(fmt, use_ampm ? "%a%I%p" : "%a%H");
 	}
 
 	/* Default is hh:mm{am,pm}. */
 	else {
-		(void)strcpy(fmt, use_ampm ? "%l:%M%p" : "%k:%M");
+		strcpy(fmt, use_ampm ? "%l:%M%p" : "%k:%M");
 	}
 
-	(void)strftime(buf, sizeof(buf), fmt, &tp);
-	(void)printf("%-7.7s", buf);
+	strftime(buf, sizeof(buf), fmt, &tp);
+	printf("%-7.7s", buf);
 }
 
 /*
@@ -92,7 +92,7 @@
 	/* If idle more than 36 hours, print as a number of days. */
 	if (idle >= 36 * 3600) {
 		int days = idle / 86400;
-		(void)printf(" %dday%s ", days, days > 1 ? "s" : " " );
+		printf(" %dday%s ", days, days > 1 ? "s" : " " );
 		if (days >= 100)
 			return (2);
 		if (days >= 10)
@@ -101,15 +101,15 @@
 
 	/* If idle more than an hour, print as HH:MM. */
 	else if (idle >= 3600)
-		(void)printf(" %2d:%02d ",
+		printf(" %2d:%02d ",
 		    (int)(idle / 3600), (int)((idle % 3600) / 60));
 
 	else if (idle / 60 == 0)
-		(void)printf("     - ");
+		printf("     - ");
 
 	/* Else print the minutes idle. */
 	else
-		(void)printf("    %2d ", (int)(idle / 60));
+		printf("    %2d ", (int)(idle / 60));
 
 	return (0); /* not idle longer than 9 days */
 }
Index: w.c
===================================================================
RCS file: /cvs/src/usr.bin/w/w.c,v
retrieving revision 1.5
diff -u -u -r1.5 w.c
--- w.c	21 Nov 2003 22:46:15 -0000	1.5
+++ w.c	29 Oct 2004 16:16:00 -0000
@@ -131,7 +131,7 @@
 	char *memf, *nlistf, *p, *x;
 	char buf[MAXHOSTNAMELEN], errbuf[_POSIX2_LINE_MAX];
 
-	(void)setlocale(LC_ALL, "");
+	setlocale(LC_ALL, "");
 	use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
 	use_comma = (*nl_langinfo(RADIXCHAR) != ',');
 
@@ -194,7 +194,7 @@
 	if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf)) == NULL)
 		errx(1, "%s", errbuf);
 
-	(void)time(&now);
+	time(&now);
 	if ((ut = fopen(_PATH_UTMP, "r")) == NULL)
 		err(1, "%s", _PATH_UTMP);
 
@@ -232,13 +232,10 @@
 		 * the true console device dev_t.
 		 */
 		if (ep->tdev == 0) {
-			int mib[2];
 			size_t size;
 
-			mib[0] = CTL_MACHDEP;
-			mib[1] = CPU_CONSDEV;
 			size = sizeof(dev_t);
-			(void)sysctl(mib, 2, &ep->tdev, &size, NULL, 0);
+			sysctlbyname("machdep.consdev", &ep->tdev, &size, NULL, 0);
 		}
 #endif
 		touched = stp->st_atime;
@@ -249,12 +246,12 @@
 		if ((ep->idle = now - touched) < 0)
 			ep->idle = 0;
 	}
-	(void)fclose(ut);
+	fclose(ut);
 
 	if (header || wcmd == 0) {
 		pr_header(&now, nusers);
 		if (wcmd == 0) {
-			(void)kvm_close(kd);
+			kvm_close(kd);
 			exit(0);
 		}
 
@@ -265,7 +262,7 @@
 #define HEADER_WHAT		"WHAT\n"
 #define WUSED  (UT_NAMESIZE + UT_LINESIZE + UT_HOSTSIZE + \
 		sizeof(HEADER_LOGIN_IDLE) + 3)	/* header width incl. spaces */ 
-		(void)printf("%-*.*s %-*.*s %-*.*s  %s", 
+		printf("%-*.*s %-*.*s %-*.*s  %s", 
 				UT_NAMESIZE, UT_NAMESIZE, HEADER_USER,
 				UT_LINESIZE, UT_LINESIZE, HEADER_TTY,
 				UT_HOSTSIZE, UT_HOSTSIZE, HEADER_FROM,
@@ -384,7 +381,7 @@
 			}
 		}
 		if (x) {
-			(void)snprintf(buf, sizeof(buf), "%s:%s", p, x);
+			snprintf(buf, sizeof(buf), "%s:%s", p, x);
 			p = buf;
 		}
 		if (dflag) {
@@ -395,11 +392,11 @@
 				    dkp->kp_thread.td_comm, MAXCOMLEN);
 				if (ptr == NULL)
 					ptr = "-";
-				(void)printf("\t\t%-9d %s\n",
+				printf("\t\t%-9d %s\n",
 				    dkp->kp_proc.p_pid, ptr);
 			}
 		}
-		(void)printf("%-*.*s %-*.*s %-*.*s ",
+		printf("%-*.*s %-*.*s %-*.*s ",
 		    UT_NAMESIZE, UT_NAMESIZE, ep->utmp.ut_name,
 		    UT_LINESIZE, UT_LINESIZE,
 		    strncmp(ep->utmp.ut_line, "tty", 3) &&
@@ -408,9 +405,9 @@
 		    UT_HOSTSIZE, UT_HOSTSIZE, *p ? p : "-");
 		pr_attime(&ep->utmp.ut_time, &now);
 		longidle = pr_idle(ep->idle);
-		(void)printf("%.*s\n", argwidth - longidle, ep->args);
+		printf("%.*s\n", argwidth - longidle, ep->args);
 	}
-	(void)kvm_close(kd);
+	kvm_close(kd);
 	exit(0);
 }
 
@@ -420,26 +417,23 @@
 	double avenrun[3];
 	time_t uptime;
 	int days, hrs, i, mins, secs;
-	int mib[2];
 	size_t size;
 	char buf[256];
 
 	/*
 	 * Print time of day.
 	 */
-	(void)strftime(buf, sizeof(buf)	- 1,
+	strftime(buf, sizeof(buf)	- 1,
 		       use_ampm	? "%l:%M%p" : "%k:%M", localtime(nowp));
 	buf[sizeof(buf) - 1] = '\0';
-	(void)printf("%s ", buf);
+	printf("%s ", buf);
 
 	/*
 	 * Print how long system has been up.
-	 * (Found by looking getting "boottime" from the kernel)
+	 * (Found by looking at "boottime" from the kernel)
 	 */
-	mib[0] = CTL_KERN;
-	mib[1] = KERN_BOOTTIME;
 	size = sizeof(boottime);
-	if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
+	if (sysctlbyname("kern.boottime", &boottime, &size, NULL, 0) != -1 &&
 	    boottime.tv_sec != 0) {
 		uptime = now - boottime.tv_sec;
 		if (uptime > 60)
@@ -450,35 +444,35 @@
 		uptime %= 3600;
 		mins = uptime / 60;
 		secs = uptime % 60;
-		(void)printf(" up");
+		printf(" up");
 		if (days > 0)
-			(void)printf(" %d day%s,", days, days > 1 ? "s" : "");
+			printf(" %d day%s,", days, days > 1 ? "s" : "");
 		if (hrs > 0 && mins > 0)
-			(void)printf(" %2d:%02d,", hrs, mins);
+			printf(" %2d:%02d,", hrs, mins);
 		else if (hrs > 0)
-			(void)printf(" %d hr%s,", hrs, hrs > 1 ? "s" : "");
+			printf(" %d hr%s,", hrs, hrs > 1 ? "s" : "");
 		else if (mins > 0)
-			(void)printf(" %d min%s,", mins, mins > 1 ? "s" : "");
+			printf(" %d min%s,", mins, mins > 1 ? "s" : "");
 		else
-			(void)printf(" %d sec%s,", secs, secs > 1 ? "s" : "");
+			printf(" %d sec%s,", secs, secs > 1 ? "s" : "");
 	}
 
-	/* Print number of users logged in to system */
-	(void)printf(" %d user%s", nusers, nusers == 1 ? "" : "s");
+	/* Print number of users logged in on system */
+	printf(" %d user%s", nusers, nusers == 1 ? "" : "s");
 
 	/*
 	 * Print 1, 5, and 15 minute load averages.
 	 */
 	if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) == -1)
-		(void)printf(", no load average information available\n");
+		printf(", no load average information available\n");
 	else {
-		(void)printf(", load averages:");
+		printf(", load averages:");
 		for (i = 0; i < (sizeof(avenrun) / sizeof(avenrun[0])); i++) {
 			if (use_comma && i > 0)
-				(void)printf(",");
-			(void)printf(" %.2f", avenrun[i]);
+				printf(",");
+			printf(" %.2f", avenrun[i]);
 		}
-		(void)printf("\n");
+		printf("\n");
 	}
 }
 
@@ -488,7 +482,7 @@
 	static struct stat sb;
 	char ttybuf[MAXPATHLEN];
 
-	(void)snprintf(ttybuf, sizeof(ttybuf), "%s%.*s", _PATH_DEV, sz, line);
+	snprintf(ttybuf, sizeof(ttybuf), "%s%.*s", _PATH_DEV, sz, line);
 	if (stat(ttybuf, &sb)) {
 		warn("%s", ttybuf);
 		return (NULL);
@@ -500,10 +494,10 @@
 usage(int wcmd)
 {
 	if (wcmd)
-		(void)fprintf(stderr,
+		fprintf(stderr,
 		    "usage: w [-dhin] [-M core] [-N system] [user ...]\n");
 	else
-		(void)fprintf(stderr, "usage: uptime\n");
+		fprintf(stderr, "usage: uptime\n");
 	exit(1);
 }
 
