* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)who.c 5.11 (Berkeley) %G%";
char *t
, *rindex(), *strcpy(), *strncpy(), *ttyname();
/* only entries with both name and line fields */
while (fread((char *)&usr
, sizeof(usr
), 1, ufp
) == 1)
if (*usr
.ut_name
&& *usr
.ut_line
)
case 2: /* who utmp_file */
while (fread((char *)&usr
, sizeof(usr
), 1, ufp
) == 1)
/* search through the utmp and find an entry for this tty */
/* strip any directory component */
while (fread((char *)&usr
, sizeof(usr
), 1, ufp
) == 1)
if (usr
.ut_name
&& !strcmp(usr
.ut_line
, p
)) {
/* well, at least we know what the tty is */
(void)strncpy(usr
.ut_line
, p
, UT_LINESIZE
);
(void)strcpy(usr
.ut_line
, "tty??");
(void)strncpy(usr
.ut_name
, pw
? pw
->pw_name
: "?", UT_NAMESIZE
);
(void)time(&usr
.ut_time
);
(void)fprintf(stderr
, "usage: who [ file ]\n who am i\n");
(void)printf("%-*.*s %-*.*s", UT_NAMESIZE
, UT_NAMESIZE
, up
->ut_name
,
UT_LINESIZE
, UT_LINESIZE
, up
->ut_line
);
(void)printf("%.12s", ctime(&up
->ut_time
) + 4);
printf("\t(%.*s)", UT_HOSTSIZE
, up
->ut_host
);
if (!(ufp
= fopen(name
, "r"))) {
(void)fprintf(stderr
, "who: %s: %s.\n", name
, strerror(errno
));