fix -n with 16-chars hostnames, modified patch from PR

PR: 11286
Submitted by:  Hans Huebner <hans@chaosradio.berlin.ccc.de>
This commit is contained in:
Andrey A. Chernov 1999-04-22 23:40:56 +00:00
parent 607c815bef
commit 9587fac012
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=45946

View File

@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94";
#endif
static const char rcsid[] =
"$Id: w.c,v 1.32 1999/01/10 15:28:37 peter Exp $";
"$Id: w.c,v 1.33 1999/03/31 21:01:39 brian Exp $";
#endif /* not lint */
/*
@ -335,7 +335,11 @@ main(argc, argv)
}
for (ep = ehead; ep != NULL; ep = ep->next) {
p = *ep->utmp.ut_host ? ep->utmp.ut_host : "-";
char host_buf[UT_HOSTSIZE + 1];
host_buf[UT_HOSTSIZE] = '\0';
strncpy(host_buf, ep->utmp.ut_host, UT_HOSTSIZE);
p = *host_buf ? host_buf : "-";
if ((x = strchr(p, ':')) != NULL)
*x++ = '\0';
if (!nflag && isdigit(*p) &&
@ -362,8 +366,7 @@ main(argc, argv)
}
}
if (x) {
(void)snprintf(buf, sizeof(buf), "%s:%.*s", p,
ep->utmp.ut_host + UT_HOSTSIZE - x, x);
(void)snprintf(buf, sizeof(buf), "%s:%s", p, x);
p = buf;
}
if (dflag) {