4 |
4 |
5 extern __thread int errno; |
5 extern __thread int errno; |
6 |
6 |
7 readfile_res* retrieve_file_1_svc(request *req, struct svc_req *rqstp) |
7 readfile_res* retrieve_file_1_svc(request *req, struct svc_req *rqstp) |
8 { |
8 { |
9 FILE *file; |
9 FILE *file; |
10 char data[1024]; |
10 filechunk data; |
11 int bytes; |
11 static readfile_res res; |
12 static readfile_res res; |
|
13 |
12 |
14 file = fopen(req->name, "r"); |
13 file = fopen(req->name, "rb"); |
15 if (file == NULL) { |
14 if (file == NULL) { |
16 res.errno = errno; |
15 res.errno = errno; |
17 return (&res); |
16 return (&res); |
18 } |
17 } |
19 |
18 |
20 xdr_free((xdrproc_t)xdr_readfile_res, (char *)&res); |
19 xdr_free((xdrproc_t)xdr_readfile_res, (char *)&res); |
21 |
20 |
22 fseek (file, req->start, SEEK_SET); |
21 fseek (file, req->start, SEEK_SET); |
23 bytes = fread(data, 1, MAXLEN, file); |
22 res.readfile_res_u.chunk.items = fread(res.readfile_res_u.chunk.data, sizeof(int), MAXLEN, file); |
24 res.readfile_res_u.chunk.data = data; |
|
25 res.readfile_res_u.chunk.bytes = bytes; |
|
26 |
23 |
27 /* |
24 /* |
28 * Return the result |
25 * Return the result |
29 */ |
26 */ |
30 res.errno = 0; |
27 res.errno = 0; |
31 fclose(file); |
28 fclose(file); |
32 return (&res); |
29 return (&res); |
33 } |
30 } |
34 |
31 |
35 int* send_file_1_svc(chunksend *rec, struct svc_req *rqstp) |
32 int* send_file_1_svc(chunksend *rec, struct svc_req *rqstp) |
36 { |
33 { |
37 FILE *file; |
34 FILE *file; |
38 int write_bytes; |
35 int write_items; |
39 static int result; |
36 static int result; |
40 |
37 |
41 file = fopen(rec->name, "a"); |
38 file = fopen(rec->name, "ab"); |
42 if (file == NULL) { |
39 if (file == NULL) { |
43 result = errno; |
40 result = errno; |
44 return &result; |
41 return &result; |
45 } |
42 } |
46 |
43 |
47 write_bytes = fwrite(rec->data, 1, rec->bytes, file); |
44 write_items = fwrite(rec->data, sizeof(int), rec->items, file); |
48 fclose(file); |
45 fclose(file); |
49 |
46 |
50 result = 0; |
47 result = 0; |
51 return &result; |
48 return &result; |
52 } |
49 } |
53 |
50 |