]> code.citadel.org Git - citadel.git/blobdiff - citadel/file_ops.c
* Fixed another fread() bug
[citadel.git] / citadel / file_ops.c
index 99009a1b7494b32dc1c5da90fea1fd34c4d90ac8..b7b0cb3f32c5935f0d4af095918b3e7acee3db65 100644 (file)
@@ -549,7 +549,7 @@ void cmd_clos(char *cmdbuf)
 /*
  * abort an upload
  */
-void abort_upl(struct CitContext *who)
+void abort_upl(CitContext *who)
 {
        if (who->upload_fp != NULL) {
                fclose(who->upload_fp);
@@ -621,7 +621,6 @@ void cmd_read(char *cmdbuf)
 {
        long start_pos;
        size_t bytes;
-       size_t actual_bytes;
        char *buf = NULL;
 
        start_pos = extract_long(cmdbuf, 0);
@@ -637,9 +636,13 @@ void cmd_read(char *cmdbuf)
        buf = malloc(bytes + 1);
 
        fseek(CC->download_fp, start_pos, 0);
-       actual_bytes = fread(buf, 1, bytes, CC->download_fp);
-       cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
-       client_write(buf, actual_bytes);
+       if (fread(buf, 1, bytes, CC->download_fp) == 1) {
+               cprintf("%d %d\n", BINARY_FOLLOWS, (int)bytes);
+               client_write(buf, bytes);
+       }
+       else {
+               cprintf("%d %s\n", ERROR, strerror(errno));
+       }
        free(buf);
 }
 
@@ -782,18 +785,20 @@ void cmd_nuop(char *cmdbuf)
 
 CTDL_MODULE_INIT(file_ops)
 {
-       CtdlRegisterProtoHook(cmd_delf, "DELF", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_movf, "MOVF", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_open, "OPEN", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_clos, "CLOS", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_uopn, "UOPN", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_ucls, "UCLS", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_read, "READ", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_writ, "WRIT", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_oimg, "OIMG", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_ndop, "NDOP", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_nuop, "NUOP", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_uimg, "UIMG", "Autoconverted. TODO: document me.");
+       if (!threading) {
+               CtdlRegisterProtoHook(cmd_delf, "DELF", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_movf, "MOVF", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_open, "OPEN", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_clos, "CLOS", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_uopn, "UOPN", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_ucls, "UCLS", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_read, "READ", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_writ, "WRIT", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_oimg, "OIMG", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_ndop, "NDOP", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_nuop, "NUOP", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_uimg, "UIMG", "Autoconverted. TODO: document me.");
+       }
         /* return our Subversion id for the Log */
        return "$Id$";
 }