From ddd15211e0895478f9b6008ff9c26c99d45a1753 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 25 Feb 2012 23:50:47 +0100 Subject: [PATCH] w: use utmp definitions to determine array sizes Signed-off-by: Sami Kerola Conflicts: w.c --- w.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/w.c b/w.c index 39a530d8..da948ba2 100644 --- a/w.c +++ b/w.c @@ -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); }