Deleted Added
sdiff udiff text old ( 28794 ) new ( 29430 )
full compact
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$";
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 <paths.h>
59#include <pwd.h>
60#include <stdio.h>
61#include <string.h>
62#include <unistd.h>
63#include <utmp.h>
64
65void done __P((void));
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
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 }
124 done();
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
289done()
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');
309 } else if (!isprint(*s) && !isspace(*s) && *s != '\007') {
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}