|
|
1.1 root 1: /*
2: receive.c
3:
4: take the file sent by "store.c" and write it locally
5: */
6: # include "defs.h"
7:
8: /* global variables */
9: struct daemonparms netd;
10:
11: main(argc,argv)
12: char **argv; {
13: FILE *fp;
14: char *p, save[40];
15: int i, n;
16: char buf[BUFSIZ];
17: long length;
18: debugflg = DBV;
19: setupdaemon(argc,argv);
20: putchar('!');
21: for(;;){
22: netd.dp_lastseqno = -1;
23: while(getreset() == BROKENREAD);
24: while((i = nread(buf,20)) == BROKENREAD);
25: if(i != 20){
26: printf("Didn't read file name\n");
27: exit(EX_USAGE);
28: }
29: for(p=buf; *p && *p != '\n' && *p != ' '; p++);
30: *p = 0;
31: printf("Creating file %s ",buf);
32: fp = fopen(buf,"w");
33: if(fp == NULL){
34: perror(buf);
35: exit(EX_OSFILE);
36: }
37: strcpy(save,buf);
38: while((i = nread(&length,4)) == BROKENREAD);
39: if(i != 4){
40: printf("Didn't read length right\n");
41: exit(EX_SOFTWARE);
42: }
43: length = fixuplong(length);
44: printf("length %ld\n",length);
45: while(length > 0){
46: i = min(length,512);
47: while((n = nread(buf,i)) == BROKENREAD);
48: length -= n;
49: fwrite(buf,1,n,fp);
50: }
51: fclose(fp);
52: printf("Finished file %s\n",save);
53: }
54: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.