w: use utmp definitions to determine array sizes

Signed-off-by: Sami Kerola <kerolasa@iki.fi>

Conflicts:

	w.c
This commit is contained in:
Sami Kerola 2012-02-25 23:50:47 +01:00 committed by Craig Small
parent 0f6b289212
commit ddd15211e0

13
w.c
View File

@ -67,9 +67,6 @@ typedef struct utmp utmp_t;
# define FROM_STRING "off"
#endif
/* Uh... same thing as UT_NAMESIZE */
#define USERSZ (sizeof u->ut_user)
/* Arbitary setting, not too big for the screen, max host size */
#define HOSTSZ 40
@ -249,7 +246,7 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from,
unsigned long long jcpu;
int ut_pid_found;
unsigned i;
char uname[USERSZ + 1] = "", tty[5 + sizeof u->ut_line + 1] = "/dev/";
char uname[UT_NAMESIZE + 1] = "", tty[5 + UT_LINESIZE + 1] = "/dev/";
const proc_t *best;
for (i = 0; i < sizeof(u->ut_line); i++)
@ -271,7 +268,7 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from,
return;
/* force NUL term for printf */
strncpy(uname, u->ut_user, USERSZ);
strncpy(uname, u->ut_user, UT_NAMESIZE);
if (formtype) {
printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, u->ut_line);
@ -404,10 +401,10 @@ int main(int argc, char **argv)
/* Get user field length from environment */
if ((env_var = getenv("PROCPS_USERLEN")) != NULL) {
userlen = atoi(env_var);
if (userlen < 8 || userlen > USERSZ) {
if (userlen < 8 || userlen > UT_NAMESIZE) {
xwarnx
(_("User length environment PROCPS_USERLEN must be between 8 and %zu, ignoring.\n"),
USERSZ);
UT_NAMESIZE);
userlen = 8;
}
}
@ -459,7 +456,7 @@ int main(int argc, char **argv)
break;
if (u->ut_type != USER_PROCESS)
continue;
if (!strncmp(u->ut_user, user, USERSZ))
if (!strncmp(u->ut_user, user, UT_NAMESIZE))
showinfo(u, longform, maxcmd, from, userlen,
fromlen);
}