home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / net / receive.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  993b  |  47 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. # include "defs.h"
  3. main(argc,argv)
  4.   char **argv; {
  5.     FILE *fp;
  6.     char *p, save[40];
  7.     int i, n;
  8.     char buf[BFS*2];
  9.     long length;
  10.     debugflg = DBV;
  11.     setupdaemon(argc,argv);
  12.     putchar('!');
  13.     for(;;){
  14.         lastseqno = -1;
  15.         while(getreset() == BROKENREAD);
  16.         while((i = nread(buf,1,20)) == BROKENREAD);
  17.         if(i != 20){
  18.             printf("Didn't read file name\n");
  19.             exit(1);
  20.             }
  21.         for(p=buf; *p && *p != '\n' && *p != ' '; p++);
  22.         *p = 0;
  23.         printf("Creating file %s ",buf);
  24.         fp = fopen(buf,"w");
  25.         if(fp == NULL){
  26.             perror(buf);
  27.             exit(1);
  28.             }
  29.         strcpy(save,buf);
  30.         while((i = nread(&length,1,4)) == BROKENREAD);
  31.         if(i != 4){
  32.             printf("Didn't read length right\n");
  33.             exit(1);
  34.             }
  35.         length = fixuplong(length);
  36.         printf("length %ld\n",length);
  37.         while(length > 0){
  38.             i = min(length,512);
  39.             while((n = nread(buf,1,i)) == BROKENREAD);
  40.             length -= n;
  41.             fwrite(buf,1,n,fp);
  42.             }
  43.         fclose(fp);
  44.         printf("Finished file %s\n",save);
  45.         }
  46.     }
  47.