Date: Fri, 20 Jul 2001 20:18:04 -0400 From: David Hill <david@phobia.ms> To: current@freebsd.org Subject: usr.bin/write/write.c patch Message-ID: <20010720201804.5491b17c.david@phobia.ms>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] Hello - I patched up write.c a bit. 1. Constified 2. Changed a strncpy to strlcpy 3. change S_IWRITE >> 3 to S_IWGRP 4. Changed fileno(stdin/stdout/stderr) to STD*_FILENO 5. cleaned up 2 pieces of code so it will compile when WARNS=2 is set. The patch is attached, and can be found at http://www.phobia.ms/patches/write.c.20072001.diff Any comments? - David Hill [-- Attachment #2 --] *** /usr/src/usr.bin/write/write.c.orig Fri Aug 27 21:07:48 1999 --- /usr/src/usr.bin/write/write.c Fri Jul 20 20:05:44 2001 *************** *** 64,75 **** #include <utmp.h> void done __P((int)); ! void do_write __P((char *, char *, uid_t)); static void usage __P((void)); ! int term_chk __P((char *, int *, time_t *, int)); void wr_fputs __P((unsigned char *s)); ! void search_utmp __P((char *, char *, char *, uid_t)); ! int utmp_chk __P((char *, char *)); int main(argc, argv) --- 64,75 ---- #include <utmp.h> void done __P((int)); ! void do_write __P((const char *, const char *, uid_t)); static void usage __P((void)); ! int term_chk __P((const char *, int *, time_t *, int)); void wr_fputs __P((unsigned char *s)); ! void search_utmp __P((const char *, const char *, char *, uid_t)); ! int utmp_chk __P((const char *, const char *)); int main(argc, argv) *************** *** 85,96 **** (void)setlocale(LC_CTYPE, ""); /* check that sender has write enabled */ ! if (isatty(fileno(stdin))) ! myttyfd = fileno(stdin); ! else if (isatty(fileno(stdout))) ! myttyfd = fileno(stdout); ! else if (isatty(fileno(stderr))) ! myttyfd = fileno(stderr); else errx(1, "can't find your tty"); if (!(mytty = ttyname(myttyfd))) --- 85,96 ---- (void)setlocale(LC_CTYPE, ""); /* check that sender has write enabled */ ! if (isatty(STDIN_FILENO)) ! myttyfd = STDIN_FILENO; ! else if (isatty(STDOUT_FILENO)) ! myttyfd = STDOUT_FILENO; ! else if (isatty(STDERR_FILENO)) ! myttyfd = STDERR_FILENO; else errx(1, "can't find your tty"); if (!(mytty = ttyname(myttyfd))) *************** *** 107,113 **** /* check args */ switch (argc) { case 2: ! search_utmp(argv[1], tty, mytty, myuid); do_write(tty, mytty, myuid); break; case 3: --- 107,113 ---- /* check args */ switch (argc) { case 2: ! search_utmp(argv[1], mytty, tty, myuid); do_write(tty, mytty, myuid); break; case 3: *************** *** 141,147 **** */ int utmp_chk(user, tty) ! char *user, *tty; { struct utmp u; int ufd; --- 141,147 ---- */ int utmp_chk(user, tty) ! const char *user, *tty; { struct utmp u; int ufd; *************** *** 172,179 **** * writing from, unless that's the only terminal with messages enabled. */ void ! search_utmp(user, tty, mytty, myuid) ! char *user, *tty, *mytty; uid_t myuid; { struct utmp u; --- 172,180 ---- * writing from, unless that's the only terminal with messages enabled. */ void ! search_utmp(user, mytty, tty, myuid) ! const char *user, *mytty; ! char *tty; uid_t myuid; { struct utmp u; *************** *** 190,197 **** while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u)) if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) { ++nloggedttys; ! (void)strncpy(atty, u.ut_line, UT_LINESIZE); ! atty[UT_LINESIZE] = '\0'; if (term_chk(atty, &msgsok, &atime, 0)) continue; /* bad term? skip */ if (myuid && !msgsok) --- 191,197 ---- while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u)) if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) { ++nloggedttys; ! (void)strlcpy(atty, u.ut_line, UT_LINESIZE); if (term_chk(atty, &msgsok, &atime, 0)) continue; /* bad term? skip */ if (myuid && !msgsok) *************** *** 227,233 **** */ int term_chk(tty, msgsokP, atimeP, showerror) ! char *tty; int *msgsokP, showerror; time_t *atimeP; { --- 227,233 ---- */ int term_chk(tty, msgsokP, atimeP, showerror) ! const char *tty; int *msgsokP, showerror; time_t *atimeP; { *************** *** 240,246 **** warn("%s", path); return(1); } ! *msgsokP = (s.st_mode & (S_IWRITE >> 3)) != 0; /* group write bit */ *atimeP = s.st_atime; return(0); } --- 240,246 ---- warn("%s", path); return(1); } ! *msgsokP = (s.st_mode & S_IWGRP) != 0; /* group write bit */ *atimeP = s.st_atime; return(0); } *************** *** 250,259 **** */ void do_write(tty, mytty, myuid) ! char *tty, *mytty; uid_t myuid; { ! register char *login, *nows; register struct passwd *pwd; time_t now; char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512]; --- 250,260 ---- */ void do_write(tty, mytty, myuid) ! const char *tty, *mytty; uid_t myuid; { ! register char const *login; ! register char *nows; register struct passwd *pwd; time_t now; char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512]; *************** *** 293,298 **** --- 294,300 ---- done(n) int n; /* signal number */ { + n = 0; (void)printf("EOF\r\n"); exit(0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010720201804.5491b17c.david>
