write.c (28794) | write.c (29430) |
---|---|
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Jef Poskanzer and Craig Leres of the Lawrence Berkeley Laboratory. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)write.c 8.1 (Berkeley) 6/6/93"; 46#endif 47static const char rcsid[] = | 1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Jef Poskanzer and Craig Leres of the Lawrence Berkeley Laboratory. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)write.c 8.1 (Berkeley) 6/6/93"; 46#endif 47static const char rcsid[] = |
48 "$Id$"; | 48 "$Id: write.c,v 1.7 1997/08/26 11:23:37 charnier Exp $"; |
49#endif /* not lint */ 50 51#include <sys/param.h> 52#include <sys/signal.h> 53#include <sys/stat.h> 54#include <sys/file.h> 55#include <sys/time.h> 56#include <ctype.h> 57#include <err.h> | 49#endif /* not lint */ 50 51#include <sys/param.h> 52#include <sys/signal.h> 53#include <sys/stat.h> 54#include <sys/file.h> 55#include <sys/time.h> 56#include <ctype.h> 57#include <err.h> |
58#include <locale.h> |
|
58#include <paths.h> 59#include <pwd.h> 60#include <stdio.h> 61#include <string.h> 62#include <unistd.h> 63#include <utmp.h> 64 | 59#include <paths.h> 60#include <pwd.h> 61#include <stdio.h> 62#include <string.h> 63#include <unistd.h> 64#include <utmp.h> 65 |
65void done __P((void)); | 66void done __P((int)); |
66void do_write __P((char *, char *, uid_t)); 67static void usage __P((void)); 68int term_chk __P((char *, int *, time_t *, int)); 69void wr_fputs __P((unsigned char *s)); 70void search_utmp __P((char *, char *, char *, uid_t)); 71int utmp_chk __P((char *, char *)); 72 73int 74main(argc, argv) 75 int argc; 76 char **argv; 77{ 78 register char *cp; 79 time_t atime; 80 uid_t myuid; 81 int msgsok, myttyfd; 82 char tty[MAXPATHLEN], *mytty; 83 | 67void do_write __P((char *, char *, uid_t)); 68static void usage __P((void)); 69int term_chk __P((char *, int *, time_t *, int)); 70void wr_fputs __P((unsigned char *s)); 71void search_utmp __P((char *, char *, char *, uid_t)); 72int utmp_chk __P((char *, char *)); 73 74int 75main(argc, argv) 76 int argc; 77 char **argv; 78{ 79 register char *cp; 80 time_t atime; 81 uid_t myuid; 82 int msgsok, myttyfd; 83 char tty[MAXPATHLEN], *mytty; 84 |
85 (void)setlocale(LC_CTYPE, ""); 86 |
|
84 /* check that sender has write enabled */ 85 if (isatty(fileno(stdin))) 86 myttyfd = fileno(stdin); 87 else if (isatty(fileno(stdout))) 88 myttyfd = fileno(stdout); 89 else if (isatty(fileno(stderr))) 90 myttyfd = fileno(stderr); 91 else --- 24 unchanged lines hidden (view full) --- 116 exit(1); 117 if (myuid && !msgsok) 118 errx(1, "%s has messages disabled on %s", argv[1], argv[2]); 119 do_write(argv[2], mytty, myuid); 120 break; 121 default: 122 usage(); 123 } | 87 /* check that sender has write enabled */ 88 if (isatty(fileno(stdin))) 89 myttyfd = fileno(stdin); 90 else if (isatty(fileno(stdout))) 91 myttyfd = fileno(stdout); 92 else if (isatty(fileno(stderr))) 93 myttyfd = fileno(stderr); 94 else --- 24 unchanged lines hidden (view full) --- 119 exit(1); 120 if (myuid && !msgsok) 121 errx(1, "%s has messages disabled on %s", argv[1], argv[2]); 122 do_write(argv[2], mytty, myuid); 123 break; 124 default: 125 usage(); 126 } |
124 done(); | 127 done(0); |
125 return (0); 126} 127 128static void 129usage() 130{ 131 (void)fprintf(stderr, "usage: write user [tty]\n"); 132 exit(1); --- 148 unchanged lines hidden (view full) --- 281 while (fgets(line, sizeof(line), stdin) != NULL) 282 wr_fputs(line); 283} 284 285/* 286 * done - cleanup and exit 287 */ 288void | 128 return (0); 129} 130 131static void 132usage() 133{ 134 (void)fprintf(stderr, "usage: write user [tty]\n"); 135 exit(1); --- 148 unchanged lines hidden (view full) --- 284 while (fgets(line, sizeof(line), stdin) != NULL) 285 wr_fputs(line); 286} 287 288/* 289 * done - cleanup and exit 290 */ 291void |
289done() | 292done(n) 293int n; /* signal number */ |
290{ 291 (void)printf("EOF\r\n"); 292 exit(0); 293} 294 295/* 296 * wr_fputs - like fputs(), but makes control characters visible and 297 * turns \n into \r\n 298 */ 299void 300wr_fputs(s) 301 register unsigned char *s; 302{ 303 304#define PUTC(c) if (putchar(c) == EOF) err(1, NULL); 305 306 for (; *s != '\0'; ++s) { 307 if (*s == '\n') { 308 PUTC('\r'); | 294{ 295 (void)printf("EOF\r\n"); 296 exit(0); 297} 298 299/* 300 * wr_fputs - like fputs(), but makes control characters visible and 301 * turns \n into \r\n 302 */ 303void 304wr_fputs(s) 305 register unsigned char *s; 306{ 307 308#define PUTC(c) if (putchar(c) == EOF) err(1, NULL); 309 310 for (; *s != '\0'; ++s) { 311 if (*s == '\n') { 312 PUTC('\r'); |
309 } else if (!isprint(*s) && !isspace(*s) && *s != '\007') { | 313 } else if (*s <= 0xA0 || /* disable upper controls */ 314 (!isprint(*s) && !isspace(*s) && *s != '\007') 315 ) { |
310 if (*s & 0x80) { 311 *s &= ~0x80; 312 PUTC('M'); 313 PUTC('-'); 314 } 315 if (iscntrl(*s)) { 316 *s ^= 0x40; 317 PUTC('^'); 318 } 319 } 320 PUTC(*s); 321 } 322 return; 323#undef PUTC 324} | 316 if (*s & 0x80) { 317 *s &= ~0x80; 318 PUTC('M'); 319 PUTC('-'); 320 } 321 if (iscntrl(*s)) { 322 *s ^= 0x40; 323 PUTC('^'); 324 } 325 } 326 PUTC(*s); 327 } 328 return; 329#undef PUTC 330} |