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
--- 33 unchanged lines hidden (view full) ---
42
43#if 0
44#ifndef lint
45static char sccsid[] = "@(#)write.c 8.1 (Berkeley) 6/6/93";
46#endif
47#endif
48
49#include <sys/cdefs.h>
50__FBSDID("$FreeBSD: head/usr.bin/write/write.c 97454 2002-05-29 13:14:51Z tjr $");
51
52#include <sys/param.h>
53#include <sys/signal.h>
54#include <sys/stat.h>
55#include <sys/file.h>
56#include <sys/time.h>
57#include <ctype.h>
58#include <err.h>
--- 22 unchanged lines hidden (view full) ---
81 register char *cp;
82 time_t atime;
83 uid_t myuid;
84 int msgsok, myttyfd;
85 char tty[MAXPATHLEN], *mytty;
86
87 (void)setlocale(LC_CTYPE, "");
88
89 while (getopt(argc, argv, "") != -1)
90 usage();
91 argc -= optind;
92 argv += optind;
93
94 /* check that sender has write enabled */
95 if (isatty(fileno(stdin)))
96 myttyfd = fileno(stdin);
97 else if (isatty(fileno(stdout)))
98 myttyfd = fileno(stdout);
99 else if (isatty(fileno(stderr)))
100 myttyfd = fileno(stderr);
101 else
--- 6 unchanged lines hidden (view full) ---
108 exit(1);
109 if (!msgsok)
110 errx(1, "you have write permission turned off");
111
112 myuid = getuid();
113
114 /* check args */
115 switch (argc) {
116 case 1:
117 search_utmp(argv[0], tty, mytty, myuid);
118 do_write(tty, mytty, myuid);
119 break;
120 case 2:
121 if (!strncmp(argv[1], _PATH_DEV, strlen(_PATH_DEV)))
122 argv[1] += strlen(_PATH_DEV);
123 if (utmp_chk(argv[0], argv[1]))
124 errx(1, "%s is not logged in on %s", argv[0], argv[1]);
125 if (term_chk(argv[1], &msgsok, &atime, 1))
126 exit(1);
127 if (myuid && !msgsok)
128 errx(1, "%s has messages disabled on %s", argv[0], argv[1]);
129 do_write(argv[1], mytty, myuid);
130 break;
131 default:
132 usage();
133 }
134 done(0);
135 return (0);
136}
137
--- 204 unchanged lines hidden ---
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
--- 33 unchanged lines hidden (view full) ---
42
43#if 0
44#ifndef lint
45static char sccsid[] = "@(#)write.c 8.1 (Berkeley) 6/6/93";
46#endif
47#endif
48
49#include <sys/cdefs.h>
50__FBSDID("$FreeBSD: head/usr.bin/write/write.c 97454 2002-05-29 13:14:51Z tjr $");
51
52#include <sys/param.h>
53#include <sys/signal.h>
54#include <sys/stat.h>
55#include <sys/file.h>
56#include <sys/time.h>
57#include <ctype.h>
58#include <err.h>
--- 22 unchanged lines hidden (view full) ---
81 register char *cp;
82 time_t atime;
83 uid_t myuid;
84 int msgsok, myttyfd;
85 char tty[MAXPATHLEN], *mytty;
86
87 (void)setlocale(LC_CTYPE, "");
88
89 while (getopt(argc, argv, "") != -1)
90 usage();
91 argc -= optind;
92 argv += optind;
93
94 /* check that sender has write enabled */
95 if (isatty(fileno(stdin)))
96 myttyfd = fileno(stdin);
97 else if (isatty(fileno(stdout)))
98 myttyfd = fileno(stdout);
99 else if (isatty(fileno(stderr)))
100 myttyfd = fileno(stderr);
101 else
--- 6 unchanged lines hidden (view full) ---
108 exit(1);
109 if (!msgsok)
110 errx(1, "you have write permission turned off");
111
112 myuid = getuid();
113
114 /* check args */
115 switch (argc) {
116 case 1:
117 search_utmp(argv[0], tty, mytty, myuid);
118 do_write(tty, mytty, myuid);
119 break;
120 case 2:
121 if (!strncmp(argv[1], _PATH_DEV, strlen(_PATH_DEV)))
122 argv[1] += strlen(_PATH_DEV);
123 if (utmp_chk(argv[0], argv[1]))
124 errx(1, "%s is not logged in on %s", argv[0], argv[1]);
125 if (term_chk(argv[1], &msgsok, &atime, 1))
126 exit(1);
127 if (myuid && !msgsok)
128 errx(1, "%s has messages disabled on %s", argv[0], argv[1]);
129 do_write(argv[1], mytty, myuid);
130 break;
131 default:
132 usage();
133 }
134 done(0);
135 return (0);
136}
137
--- 204 unchanged lines hidden ---