connect.c

pennmush/src/connect.c · 452 B

From the archive pennmush-1.7.2p10.tar.gz

Download the archive   « Back to the archive contents

#include <stdio.h>

main(argc, argv)
    int argc;
    char *argv[];
{
  char buff[BUFFER_LEN];
  int child;

  FILE *fi = fopen(argv[1], "r+");
  if (!(child = fork())) {
    int a;
    while (-1 != (a = read(fileno(fi), buff, 1023))) {
      if (!a) {
	sleep(1);
	continue;
      }
      write(fileno(stdout), buff, a);
    }
    exit(1);
  }
  while (fgets(buff, 1023, stdin)) {
    fprintf(fi, "%s", buff);
    fflush(fi);
  }
  kill(child, 9);
}

Site Stats

Snippets: 1791
Codebases: 571