Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Oct 2014 05:04:31 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r272728 - head/usr.bin/w
Message-ID:  <201410080504.s9854Vbd044602@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
-}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410080504.s9854Vbd044602>