- 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);