]> granicus.if.org Git - procps-ng/commitdiff
w: use utmp definitions to determine array sizes
authorSami Kerola <kerolasa@iki.fi>
Sat, 25 Feb 2012 22:50:47 +0000 (23:50 +0100)
committerCraig Small <csmall@enc.com.au>
Sat, 3 Mar 2012 21:20:39 +0000 (08:20 +1100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Conflicts:

w.c

w.c

diff --git a/w.c b/w.c
index 39a530d81979729b16341e92bdb4ca62a9a98097..da948ba2507e180ead2d793aab864d03dc1db93c 100644 (file)
--- 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);
                }