50c50
< __FBSDID("$FreeBSD: head/usr.bin/write/write.c 173572 2007-11-12 20:02:21Z jhb $");
---
> __FBSDID("$FreeBSD: head/usr.bin/write/write.c 200160 2009-12-05 20:22:26Z ed $");
64a65,66
> #define _ULOG_POSIX_NAMES
> #include <ulog.h>
66d67
< #include <utmp.h>
149,150c150
< struct utmp u;
< int ufd;
---
> struct utmpx lu, *u;
152,158c152,157
< if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0)
< return(0); /* ignore error, shouldn't happen anyway */
<
< while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u))
< if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0 &&
< strncmp(tty, u.ut_line, sizeof(u.ut_line)) == 0) {
< (void)close(ufd);
---
> strncpy(lu.ut_line, tty, sizeof lu.ut_line);
> setutxent();
> while ((u = getutxline(&lu)) != NULL)
> if (u->ut_type == USER_PROCESS &&
> strcmp(user, u->ut_user) == 0) {
> endutxent();
161,162c160
<
< (void)close(ufd);
---
> endutxent();
180c178
< struct utmp u;
---
> struct utmpx *u;
182,183c180
< int ufd, nloggedttys, nttys, msgsok, user_is_me;
< char atty[UT_LINESIZE + 1];
---
> int nloggedttys, nttys, msgsok, user_is_me;
185,187d181
< if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0)
< err(1, "utmp");
<
191,192c185,189
< while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u))
< if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) {
---
>
> setutxent();
> while ((u = getutxent()) != NULL)
> if (u->ut_type == USER_PROCESS &&
> strcmp(user, u->ut_user) == 0) {
194,196c191
< (void)strncpy(atty, u.ut_line, UT_LINESIZE);
< atty[UT_LINESIZE] = '\0';
< if (term_chk(atty, &msgsok, &atime, 0))
---
> if (term_chk(u->ut_line, &msgsok, &atime, 0))
200c195
< if (strcmp(atty, mytty) == 0) {
---
> if (strcmp(u->ut_line, mytty) == 0) {
207c202
< (void)strcpy(tty, atty);
---
> (void)strlcpy(tty, u->ut_line, MAXPATHLEN);
209a205
> endutxent();
211d206
< (void)close(ufd);
216c211
< (void)strcpy(tty, mytty);
---
> (void)strlcpy(tty, mytty, MAXPATHLEN);
< __FBSDID("$FreeBSD: head/usr.bin/write/write.c 173572 2007-11-12 20:02:21Z jhb $");
---
> __FBSDID("$FreeBSD: head/usr.bin/write/write.c 200160 2009-12-05 20:22:26Z ed $");
64a65,66
> #define _ULOG_POSIX_NAMES
> #include <ulog.h>
66d67
< #include <utmp.h>
149,150c150
< struct utmp u;
< int ufd;
---
> struct utmpx lu, *u;
152,158c152,157
< if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0)
< return(0); /* ignore error, shouldn't happen anyway */
<
< while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u))
< if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0 &&
< strncmp(tty, u.ut_line, sizeof(u.ut_line)) == 0) {
< (void)close(ufd);
---
> strncpy(lu.ut_line, tty, sizeof lu.ut_line);
> setutxent();
> while ((u = getutxline(&lu)) != NULL)
> if (u->ut_type == USER_PROCESS &&
> strcmp(user, u->ut_user) == 0) {
> endutxent();
161,162c160
<
< (void)close(ufd);
---
> endutxent();
180c178
< struct utmp u;
---
> struct utmpx *u;
182,183c180
< int ufd, nloggedttys, nttys, msgsok, user_is_me;
< char atty[UT_LINESIZE + 1];
---
> int nloggedttys, nttys, msgsok, user_is_me;
185,187d181
< if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0)
< err(1, "utmp");
<
191,192c185,189
< while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u))
< if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) {
---
>
> setutxent();
> while ((u = getutxent()) != NULL)
> if (u->ut_type == USER_PROCESS &&
> strcmp(user, u->ut_user) == 0) {
194,196c191
< (void)strncpy(atty, u.ut_line, UT_LINESIZE);
< atty[UT_LINESIZE] = '\0';
< if (term_chk(atty, &msgsok, &atime, 0))
---
> if (term_chk(u->ut_line, &msgsok, &atime, 0))
200c195
< if (strcmp(atty, mytty) == 0) {
---
> if (strcmp(u->ut_line, mytty) == 0) {
207c202
< (void)strcpy(tty, atty);
---
> (void)strlcpy(tty, u->ut_line, MAXPATHLEN);
209a205
> endutxent();
211d206
< (void)close(ufd);
216c211
< (void)strcpy(tty, mytty);
---
> (void)strlcpy(tty, mytty, MAXPATHLEN);