static char *sccsid
= "@(#)write.c 4.6 %G%";
#define NMAX sizeof(ubuf.ut_name)
#define LMAX sizeof(ubuf.ut_line)
int signum
[] = {SIGHUP
, SIGINT
, SIGQUIT
, 0};
struct tm
*localclock
= localtime( &clock
);
printf("usage: write user [ttyname]\n");
if ((uf
= fopen("/etc/utmp", "r")) == NULL
) {
printf("cannot open /etc/utmp\n");
printf("Can't find your tty\n");
if (stat(mytty
, &stbuf
) < 0) {
printf("Can't stat your tty\n");
if ((stbuf
.st_mode
&02) == 0) {
printf("You have write permission turned off.\n");
mytty
= rindex(mytty
, '/') + 1;
while (fread((char *)&ubuf
, sizeof(ubuf
), 1, uf
) == 1) {
if (ubuf
.ut_name
[0] == '\0')
if (strcmp(ubuf
.ut_line
, mytty
)==0) {
if (him
[0] != '-' || him
[1] != 0)
if (c2
== 0 || c2
== ' ')
strcat(histty
, ubuf
.ut_line
);
if (logcnt
==0 && histty
[0]=='\0') {
printf("%s not logged in.\n", him
);
if (histtya
==0 && logcnt
> 1) {
printf("%s logged more than once\nwriting to %s\n", him
, histty
+5);
printf(" not on that tty\n"); else
printf(" not logged in\n");
if (access(histty
, 0) < 0) {
if ((tf
= fopen(histty
, "w")) == NULL
)
if (fstat(fileno(tf
), &stbuf
) < 0)
if ((stbuf
.st_mode
&02) == 0)
gethostname(hostname
, sizeof (hostname
));
fprintf(tf
, "\r\nMessage from ");
fprintf(tf
, "%s!%s on %s at %d:%02d ...\r\n\a\a\a",
hostname
, me
, mytty
, localclock
->tm_hour
, localclock
->tm_min
);
if (write(fileno(tf
), buf
, i
) != i
) {
printf("\n\7Write failed (%s logged out?)\n", him
);
write(fileno(tf
), "\r", 1);
printf("Permission denied\n");
printf("Timeout opening their tty\n");
getenv("SHELL") : "/bin/sh", "sh", "-c", bp
+1, 0);
while (wait((int *)NULL
) != i
)
for (i
=0; signum
[i
]; i
++)