X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Ffile_ops.c;fp=citadel%2Ffile_ops.c;h=20bc03b68af2f900e6693061238a18f4901c596e;hb=d1dc3f670a90681177131b9fe656503c0f1a1147;hp=ee2e93a05f2ddae13451f3ca52bad8746b328114;hpb=49bc8625b31191cb87276fce46695f8badfe4105;p=citadel.git diff --git a/citadel/file_ops.c b/citadel/file_ops.c index ee2e93a05..20bc03b68 100644 --- a/citadel/file_ops.c +++ b/citadel/file_ops.c @@ -641,7 +641,6 @@ void cmd_ucls(char *cmd) } - /* * read from the download file */ @@ -649,9 +648,9 @@ void cmd_read(char *cmdbuf) { long start_pos; size_t bytes; - size_t actual_bytes; - char *buf = NULL; + char buf[SIZ]; + /* The client will transmit its requested offset and byte count */ start_pos = extract_long(cmdbuf, 0); bytes = extract_int(cmdbuf, 1); @@ -661,26 +660,24 @@ void cmd_read(char *cmdbuf) return; } - buf = mmap(NULL, - CC->download_fp_total, - PROT_READ, - MAP_PRIVATE, - fileno(CC->download_fp), - 0); - - actual_bytes = CC->download_fp_total - start_pos; - if ((actual_bytes > 0) && (buf != NULL)) { - cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes); - client_write(buf + start_pos, actual_bytes); + /* If necessary, reduce the byte count to the size of our buffer */ + if (bytes > sizeof(buf)) { + bytes = sizeof(buf); + } + + fseek(CC->download_fp, start_pos, 0); + bytes = fread(buf, 1, bytes, CC->download_fp); + if (bytes > 0) { + /* Tell the client the actual byte count and transmit it */ + cprintf("%d %d\n", BINARY_FOLLOWS, (int)bytes); + client_write(buf, bytes); } else { cprintf("%d %s\n", ERROR, strerror(errno)); } - munmap(buf, CC->download_fp_total); } - /* * write to the upload file */