diff options
Diffstat (limited to 'src/who.c')
-rw-r--r-- | src/who.c | 21 |
1 files changed, 6 insertions, 15 deletions
@@ -1,5 +1,5 @@ /* GNU's who. - Copyright (C) 1992-2012 Free Software Foundation, Inc. + Copyright (C) 1992-2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -342,23 +342,15 @@ print_user (const STRUCT_UTMP *utmp_ent, time_t boottime) #define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1) char line[sizeof (utmp_ent->ut_line) + DEV_DIR_LEN + 1]; + char *p = line; PIDSTR_DECL_AND_INIT (pidstr, utmp_ent); /* Copy ut_line into LINE, prepending '/dev/' if ut_line is not already an absolute file name. Some systems may put the full, absolute file name in ut_line. */ - if (utmp_ent->ut_line[0] == '/') - { - strncpy (line, utmp_ent->ut_line, sizeof (utmp_ent->ut_line)); - line[sizeof (utmp_ent->ut_line)] = '\0'; - } - else - { - strcpy (line, DEV_DIR_WITH_TRAILING_SLASH); - strncpy (line + DEV_DIR_LEN, utmp_ent->ut_line, - sizeof (utmp_ent->ut_line)); - line[DEV_DIR_LEN + sizeof (utmp_ent->ut_line)] = '\0'; - } + if ( ! IS_ABSOLUTE_FILE_NAME (utmp_ent->ut_line)) + p = stpcpy (p, DEV_DIR_WITH_TRAILING_SLASH); + stzncpy (p, utmp_ent->ut_line, sizeof (utmp_ent->ut_line)); if (stat (line, &stats) == 0) { @@ -384,8 +376,7 @@ print_user (const STRUCT_UTMP *utmp_ent, time_t boottime) char *display = NULL; /* Copy the host name into UT_HOST, and ensure it's nul terminated. */ - strncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host)); - ut_host[sizeof (utmp_ent->ut_host)] = '\0'; + stzncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host)); /* Look for an X display. */ display = strchr (ut_host, ':'); |