Revert d36da34581cd277a2face04a11cdb8f81d8d2121 in stable.
authorArt Cancro <ajc@citadel.org>
Fri, 17 Dec 2010 19:21:03 +0000 (14:21 -0500)
committerArt Cancro <ajc@citadel.org>
Fri, 17 Dec 2010 19:21:03 +0000 (14:21 -0500)
citadel/context.h
citadel/file_ops.c

index 322061e65471e47a135420c28beada3f4000d0b9..6992db9cfbfe650e95490286dbb4088f2aff46b9 100644 (file)
@@ -77,7 +77,6 @@ struct CitContext {
        char cs_inet_fn[128];                   /* Friendly-name of outbound Internet mail */
 
        FILE *download_fp;      /* Fields relating to file transfer */
-       size_t download_fp_total;
        char download_desired_section[128];
        FILE *upload_fp;
        char upl_file[256];
index 0e01031ff1a434d53815413826af3eca50ddaee0..ada35251401c8489c25c0e5e8fef1af54fc73217 100644 (file)
@@ -12,7 +12,6 @@
 #include <ctype.h>
 #include <string.h>
 #include <sys/stat.h>
-#include <sys/mman.h>
 
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
@@ -234,7 +233,6 @@ void OpenCmdResult(char *filename, const char *mime_type)
        long filesize;
 
        fstat(fileno(CC->download_fp), &statbuf);
-       CC->download_fp_total = statbuf.st_size;
        filesize = (long) statbuf.st_size;
        modtime = (time_t) statbuf.st_mtime;
 
@@ -653,22 +651,20 @@ 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)) {
+       if (bytes > 100000) bytes = 100000;
+       buf = malloc(bytes + 1);
+
+       fseek(CC->download_fp, start_pos, 0);
+
+       actual_bytes = fread(buf, 1, bytes, CC->download_fp);
+       if (actual_bytes > 0) {
                cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
-               client_write(buf + start_pos, actual_bytes);
+               client_write(bufbytes);
        }
        else {
                cprintf("%d %s\n", ERROR, strerror(errno));
        }
-       munmap(buf, CC->download_fp_total);
+       free(buf);
 }
 
 
@@ -754,7 +750,6 @@ void cmd_ndop(char *cmdbuf)
        CC->dl_is_net = 1;
 
        stat(pathname, &statbuf);
-       CC->download_fp_total = statbuf.st_size;
        cprintf("%d %ld\n", CIT_OK, (long)statbuf.st_size);
 }