#include <sys/stat.h>
#include <signal.h>
#include <utmp.h>
+#include <time.h>
char *strcat();
char *strcpy();
char histty[32];
char *histtya;
char *ttyname();
-char *rindex(), *index();
+char *rindex();
int logcnt;
int eof();
int timout();
FILE *tf;
+char *getenv();
main(argc, argv)
char *argv[];
register i;
register FILE *uf;
int c1, c2;
+ long clock = time( 0 );
+ struct tm *localtime();
+ struct tm *localclock = localtime( &clock );
if(argc < 2) {
printf("usage: write user [ttyname]\n");
printf("Can't find your tty\n");
exit(1);
}
- mytty = index(mytty+1, '/') + 1;
+ mytty = rindex(mytty, '/') + 1;
if (histtya) {
strcpy(histty, "/dev/");
strcat(histty, histtya);
exit(1);
}
if (access(histty, 0) < 0) {
- printf("%s: ", histty);
printf("No such tty\n");
exit(1);
}
if ((stbuf.st_mode&02) == 0)
goto perm;
sigs(eof);
- fprintf(tf, "Message from ");
+ fprintf(tf, "\r\nMessage from ");
#ifdef interdata
fprintf(tf, "(Interdata) " );
#endif
- fprintf(tf, "%s %s...\n\a\a\a", me, mytty);
+ fprintf(tf, "%s on %s at %d:%02d ...\r\n\a\a\a"
+ , me, mytty , localclock -> tm_hour , localclock -> tm_min );
fflush(tf);
for(;;) {
char buf[128];
continue;
}
write(fileno(tf), buf, i);
+ if ( buf[ i - 1 ] == '\n' )
+ write( fileno( tf ) , "\r" , 1 );
}
perm:
timout()
{
- printf("Timeout opening his tty\n");
+ printf("Timeout opening their tty\n");
exit(1);
}
eof()
{
- fprintf(tf, "EOF\n");
+ fprintf(tf, "EOF\r\n");
exit(0);
}
}
if(i == 0) {
sigs((int (*)())0);
- execl("/bin/sh", "sh", "-c", bp+1, 0);
+ execl(getenv("SHELL") ? getenv("SHELL") : "/bin/sh", "sh", "-c", bp+1, 0);
exit(0);
}
while(wait((int *)NULL) != i)