svn commit: r272728 - head/usr.bin/w

Eitan Adler eadler at FreeBSD.org
Wed Oct 8 05:04:32 UTC 2014


Author: eadler
Date: Wed Oct  8 05:04:31 2014
New Revision: 272728
URL: https://svnweb.freebsd.org/changeset/base/272728

Log:
  don't reinvent the wheel: rely on basename(3)
  
  Reviewed by:	nwhitehorn

Modified:
  head/usr.bin/w/w.c

Modified: head/usr.bin/w/w.c
==============================================================================
--- head/usr.bin/w/w.c	Wed Oct  8 04:42:56 2014	(r272727)
+++ head/usr.bin/w/w.c	Wed Oct  8 05:04:31 2014	(r272728)
@@ -68,6 +68,7 @@ static const char sccsid[] = "@(#)w.c	8.
 #include <fcntl.h>
 #include <kvm.h>
 #include <langinfo.h>
+#include <libgen.h>
 #include <libutil.h>
 #include <limits.h>
 #include <locale.h>
@@ -121,7 +122,6 @@ static struct entry {
 static void		 pr_header(time_t *, int);
 static struct stat	*ttystat(char *);
 static void		 usage(int);
-static int		 this_is_uptime(const char *s);
 
 char *fmt_argv(char **, char *, char *, size_t);	/* ../../bin/ps/fmt.c */
 
@@ -144,7 +144,7 @@ main(int argc, char *argv[])
 	use_comma = (*nl_langinfo(RADIXCHAR) != ',');
 
 	/* Are we w(1) or uptime(1)? */
-	if (this_is_uptime(argv[0]) == 0) {
+	if (strcmp(basename(argv[0]), "uptime") == 0) {
 		wcmd = 0;
 		p = "";
 	} else {
@@ -512,17 +512,3 @@ usage(int wcmd)
 		(void)fprintf(stderr, "usage: uptime\n");
 	exit(1);
 }
-
-static int 
-this_is_uptime(const char *s)
-{
-	const char *u;
-
-	if ((u = strrchr(s, '/')) != NULL)
-		++u;
-	else
-		u = s;
-	if (strcmp(u, "uptime") == 0)
-		return (0);
-	return (-1);
-}


More information about the svn-src-head mailing list