diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-04-12 18:38:12 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-04-12 18:38:12 -0400 |
commit | 5bbbb3676151cc07f81e23d5970bd0db0823df39 (patch) | |
tree | 881a10c8ef5ab023e8a89d7898019b4a7f308e9b | |
parent | 66b91392b453bfc602ac01de0de309031fd36833 (diff) |
move username check from output to utmpx_state()
-rw-r--r-- | who.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -36,6 +36,10 @@ char utmpx_state(const struct utmpx *u) snprintf(term, sizeof(term), "/dev/%s", u->ut_line); struct stat st; + if (u->ut_user[0] == '\0') { + return ' '; + } + if (stat(term, &st) == -1) { return '?'; } @@ -140,7 +144,7 @@ int main(int argc, char *argv[]) struct utmpx *u = NULL; while ((u = getutxent()) != NULL) { if (flags == QUICK) { - printf("%s\n", u->ut_user); + printf("%*s\n", (int)(sizeof(u->ut_user)), u->ut_user); continue; } @@ -163,11 +167,7 @@ int main(int argc, char *argv[]) printf("%-12s\t", u->ut_user); if (flags & TERMINAL) { - if (u->ut_user[0] == '\0') { - printf(" "); - } else { - printf("%c ", utmpx_state(u)); - } + printf("%c ", utmpx_state(u)); } printf("%-8s\t", u->ut_line); |