1*8283Scomay static char sccsid[] = "@(#)receive.c 4.1 (Berkeley) 10/02/82";
2*8283Scomay
3*8283Scomay /*
4*8283Scomay receive.c
5*8283Scomay
6*8283Scomay take the file sent by "store.c" and write it locally
7*8283Scomay */
8*8283Scomay # include "defs.h"
9*8283Scomay
10*8283Scomay /* global variables */
11*8283Scomay struct daemonparms netd;
12*8283Scomay
main(argc,argv)13*8283Scomay main(argc,argv)
14*8283Scomay char **argv; {
15*8283Scomay FILE *fp;
16*8283Scomay char *p, save[40];
17*8283Scomay int i, n;
18*8283Scomay char buf[BUFSIZ];
19*8283Scomay long length;
20*8283Scomay debugflg = DBV;
21*8283Scomay setupdaemon(argc,argv);
22*8283Scomay putchar('!');
23*8283Scomay for(;;){
24*8283Scomay initseqno();
25*8283Scomay while((i = nread(buf,20)) == BROKENREAD);
26*8283Scomay if(i != 20){
27*8283Scomay printf("Didn't read file name\n");
28*8283Scomay exit(EX_USAGE);
29*8283Scomay }
30*8283Scomay for(p=buf; *p && *p != '\n' && *p != ' '; p++);
31*8283Scomay *p = 0;
32*8283Scomay printf("Creating file %s ",buf);
33*8283Scomay fp = fopen(buf,"w");
34*8283Scomay if(fp == NULL){
35*8283Scomay fp = fopen(buf,"w");
36*8283Scomay exit(EX_OSFILE);
37*8283Scomay }
38*8283Scomay strcpy(save,buf);
39*8283Scomay while((i = nread(buf,10)) == BROKENREAD);
40*8283Scomay if(i != 10){
41*8283Scomay printf("Didn't read length right\n");
42*8283Scomay exit(EX_SOFTWARE);
43*8283Scomay }
44*8283Scomay length = atol(buf+1);
45*8283Scomay printf("length %ld\n",length);
46*8283Scomay while(length > 0){
47*8283Scomay i = min(length,512);
48*8283Scomay while((n = nread(buf,i)) == BROKENREAD);
49*8283Scomay length -= n;
50*8283Scomay fwrite(buf,1,n,fp);
51*8283Scomay }
52*8283Scomay fclose(fp);
53*8283Scomay printf("Finished file %s\n",save);
54*8283Scomay }
55*8283Scomay }
56