don't reinvent the wheel: rely on basename(3)

Reviewed by:	nwhitehorn
This commit is contained in:
Eitan Adler 2014-10-08 05:04:31 +00:00
parent 0999f75a2f
commit 920aa23dad
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=272728

View file

@ -68,6 +68,7 @@ static const char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94";
#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);
}