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

  1. /*
  2.  * Sends a file through named pipe "auxin" to the CP/M simulation
  3.  *
  4.  * Copyright (C) 1988 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. #if defined(COHERENT) && !defined(_I386)
  13. #include <sys/fcntl.h>
  14. #else
  15. #include <fcntl.h>
  16. #endif
  17.  
  18. char buf[BUFSIZ];
  19. char cr = '\r';
  20. int fdout, fdin;
  21. void exit(), perror();
  22.  
  23. main(argc,argv)
  24. int argc;
  25. char *argv[];
  26. {
  27.     register int readed;
  28.  
  29.     if (argc != 2) {
  30.         puts("usage: send filname &");
  31.         exit(1);
  32.     }
  33.     if ((fdin = open(argv[1], O_RDONLY)) == -1) {
  34.         perror(argv[1]);
  35.         exit(1);
  36.     }
  37.     if ((fdout = open("auxin", O_WRONLY)) == -1) {
  38.         perror("pipe auxin");
  39.         exit(1);
  40.     }
  41.     while ((readed = read(fdin, buf, BUFSIZ)) == BUFSIZ)
  42.         sendbuf(BUFSIZ);
  43.     if (readed)
  44.         sendbuf(readed);
  45.     close(fdin);
  46.     close(fdout);
  47.     exit(0);
  48. }
  49.  
  50. sendbuf(size)
  51. register int size;
  52. {
  53.     register char *s = buf;
  54.  
  55.     while (s - buf < size) {
  56.         if (*s == '\n')
  57.             write(fdout, (char *) &cr, 1);
  58.         write(fdout, s++, 1);
  59.     }
  60. }
  61.