Deleted Added
full compact
write.c (216370) write.c (231586)
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

--- 29 unchanged lines hidden (view full) ---

38
39#if 0
40#ifndef lint
41static char sccsid[] = "@(#)write.c 8.1 (Berkeley) 6/6/93";
42#endif
43#endif
44
45#include <sys/cdefs.h>
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

--- 29 unchanged lines hidden (view full) ---

38
39#if 0
40#ifndef lint
41static char sccsid[] = "@(#)write.c 8.1 (Berkeley) 6/6/93";
42#endif
43#endif
44
45#include <sys/cdefs.h>
46__FBSDID("$FreeBSD: head/usr.bin/write/write.c 216370 2010-12-11 08:32:16Z joel $");
46__FBSDID("$FreeBSD: head/usr.bin/write/write.c 231586 2012-02-13 14:40:15Z glebius $");
47
48#include <sys/param.h>
49#include <sys/signal.h>
50#include <sys/stat.h>
51#include <sys/file.h>
52#include <sys/time.h>
53#include <ctype.h>
54#include <err.h>
55#include <locale.h>
56#include <paths.h>
57#include <pwd.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
61#include <unistd.h>
62#include <utmpx.h>
47
48#include <sys/param.h>
49#include <sys/signal.h>
50#include <sys/stat.h>
51#include <sys/file.h>
52#include <sys/time.h>
53#include <ctype.h>
54#include <err.h>
55#include <locale.h>
56#include <paths.h>
57#include <pwd.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
61#include <unistd.h>
62#include <utmpx.h>
63#include <wchar.h>
64#include <wctype.h>
63
64void done(int);
65void do_write(char *, char *, uid_t);
66static void usage(void);
67int term_chk(char *, int *, time_t *, int);
65
66void done(int);
67void do_write(char *, char *, uid_t);
68static void usage(void);
69int term_chk(char *, int *, time_t *, int);
68void wr_fputs(unsigned char *s);
70void wr_fputs(wchar_t *s);
69void search_utmp(char *, char *, char *, uid_t);
70int utmp_chk(char *, char *);
71
72int
73main(int argc, char **argv)
74{
75 time_t atime;
76 uid_t myuid;

--- 161 unchanged lines hidden (view full) ---

238 */
239void
240do_write(char *tty, char *mytty, uid_t myuid)
241{
242 const char *login;
243 char *nows;
244 struct passwd *pwd;
245 time_t now;
71void search_utmp(char *, char *, char *, uid_t);
72int utmp_chk(char *, char *);
73
74int
75main(int argc, char **argv)
76{
77 time_t atime;
78 uid_t myuid;

--- 161 unchanged lines hidden (view full) ---

240 */
241void
242do_write(char *tty, char *mytty, uid_t myuid)
243{
244 const char *login;
245 char *nows;
246 struct passwd *pwd;
247 time_t now;
246 char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512];
248 char path[MAXPATHLEN], host[MAXHOSTNAMELEN];
249 wchar_t line[512];
247
248 /* Determine our login name before we reopen() stdout */
249 if ((login = getlogin()) == NULL) {
250 if ((pwd = getpwuid(myuid)))
251 login = pwd->pw_name;
252 else
253 login = "???";
254 }

--- 9 unchanged lines hidden (view full) ---

264 if (gethostname(host, sizeof(host)) < 0)
265 (void)strcpy(host, "???");
266 now = time((time_t *)NULL);
267 nows = ctime(&now);
268 nows[16] = '\0';
269 (void)printf("\r\n\007\007\007Message from %s@%s on %s at %s ...\r\n",
270 login, host, mytty, nows + 11);
271
250
251 /* Determine our login name before we reopen() stdout */
252 if ((login = getlogin()) == NULL) {
253 if ((pwd = getpwuid(myuid)))
254 login = pwd->pw_name;
255 else
256 login = "???";
257 }

--- 9 unchanged lines hidden (view full) ---

267 if (gethostname(host, sizeof(host)) < 0)
268 (void)strcpy(host, "???");
269 now = time((time_t *)NULL);
270 nows = ctime(&now);
271 nows[16] = '\0';
272 (void)printf("\r\n\007\007\007Message from %s@%s on %s at %s ...\r\n",
273 login, host, mytty, nows + 11);
274
272 while (fgets(line, sizeof(line), stdin) != NULL)
275 while (fgetws(line, sizeof(line)/sizeof(wchar_t), stdin) != NULL)
273 wr_fputs(line);
274}
275
276/*
277 * done - cleanup and exit
278 */
279void
280done(int n __unused)
281{
282 (void)printf("EOF\r\n");
283 exit(0);
284}
285
286/*
287 * wr_fputs - like fputs(), but makes control characters visible and
288 * turns \n into \r\n
289 */
290void
276 wr_fputs(line);
277}
278
279/*
280 * done - cleanup and exit
281 */
282void
283done(int n __unused)
284{
285 (void)printf("EOF\r\n");
286 exit(0);
287}
288
289/*
290 * wr_fputs - like fputs(), but makes control characters visible and
291 * turns \n into \r\n
292 */
293void
291wr_fputs(unsigned char *s)
294wr_fputs(wchar_t *s)
292{
293
295{
296
294#define PUTC(c) if (putchar(c) == EOF) err(1, NULL);
297#define PUTC(c) if (putwchar(c) == WEOF) err(1, NULL);
295
298
296 for (; *s != '\0'; ++s) {
297 if (*s == '\n') {
298 PUTC('\r');
299 } else if (((*s & 0x80) && *s < 0xA0) ||
300 /* disable upper controls */
301 (!isprint(*s) && !isspace(*s) &&
302 *s != '\a' && *s != '\b')
303 ) {
304 if (*s & 0x80) {
305 *s &= ~0x80;
306 PUTC('M');
307 PUTC('-');
308 }
309 if (iscntrl(*s)) {
310 *s ^= 0x40;
311 PUTC('^');
312 }
299 for (; *s != L'\0'; ++s) {
300 if (*s == L'\n') {
301 PUTC(L'\r');
302 PUTC(L'\n');
303 } else if (iswprint(*s) || iswspace(*s)) {
304 PUTC(*s);
305 } else {
306 wprintf(L"<0x%X>", *s);
313 }
307 }
314 PUTC(*s);
315 }
316 return;
317#undef PUTC
318}
308 }
309 return;
310#undef PUTC
311}