home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / emulator / unix / z80pack / cpmsim / srccpm / receive.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-11  |  974 b   |  58 lines

  1. /*
  2.  * Receive a file out of the named pipe "auxout" from CP/M simulation
  3.  *
  4.  * Copyright (C) 1988-93 by Udo Munk
  5.  *
  6.  * History:
  7.  * 05-OKT-88 Development on TARGON/35 with AT&T Unix System V.3
  8.  * 11-MAR-93 comments in english and ported to COHERENT 4.0
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <signal.h>
  13. #if defined(COHERENT) && !defined(_I386)
  14. #include <sys/fcntl.h>
  15. #else
  16. #include <fcntl.h>
  17. #endif
  18.  
  19. int fdin, fdout;
  20.  
  21. main(argc, argv)
  22. int argc;
  23. char *argv[];
  24. {
  25.     char c;
  26.     void exit(), perror(), int_handler();
  27.  
  28.     if (argc != 2) {
  29.         puts("usage: receive filname &");
  30.         exit(1);
  31.     }
  32.     if ((fdin = open("auxout", O_RDONLY)) == -1) {
  33.         perror("pipe auxout");
  34.         exit(1);
  35.     }
  36.     if ((fdout = creat(argv[1], 0644)) == -1) {
  37.         perror(argv[1]);
  38.         exit(1);
  39.     }
  40.  
  41.     signal(SIGINT, SIG_IGN);
  42.     signal(SIGQUIT, SIG_IGN);
  43.     signal(SIGHUP, int_handler);
  44.  
  45.     for (;;) {
  46.         if (read(fdin, &c, 1) == 1)
  47.             if (c != '\r')
  48.                 write(fdout, &c, 1);
  49.     }
  50. }
  51.  
  52. void int_handler()
  53. {
  54.     close(fdin);
  55.     close(fdout);
  56.     exit(0);
  57. }
  58.