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