]> code.citadel.org Git - citadel.git/blobdiff - citadel/config.c
Began tweaking out some calendar stuff in preparation for CalDAV. Mike Shaver is...
[citadel.git] / citadel / config.c
index dad9eaee1437075d76e8f1a5e84b2fdf98f24fc1..bc9a4128e9bd0b9c8cc5c0793797cee82d5a8bf1 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * Read and write the citadel.config file
  *
  * Copyright (c) 1987-2009 by the citadel.org team
 #include "server.h"
 #include "config.h"
 
+
+#include "ctdl_module.h"
+
+
 struct config config;
 
 /*
@@ -43,6 +45,7 @@ struct config config;
 void get_config(void) {
        FILE *cfp;
        struct stat st;
+       int rv;
 
        if (chdir(ctdl_bbsbase_dir) != 0) {
                fprintf(stderr,
@@ -62,7 +65,14 @@ void get_config(void) {
                                strerror(errno));
                exit(CTDLEXIT_CONFIG);
        }
-       fread((char *) &config, sizeof(struct config), 1, cfp);
+       memset(&config, 0, sizeof(struct config));
+       rv = fread((char *) &config, sizeof(struct config), 1, cfp);
+       if (rv != 1)
+       {
+               fprintf(stderr, 
+                       "Warning: The config file %s has unexpected size. \n",
+                       file_citadel_config);
+       }
        if (fstat(fileno(cfp), &st)) {
                perror(file_citadel_config);
                exit(CTDLEXIT_CONFIG);
@@ -163,11 +173,15 @@ void get_config(void) {
 void put_config(void)
 {
        FILE *cfp;
+       int rv;
 
        if ((cfp = fopen(file_citadel_config, "rb+")) == NULL)
                perror(file_citadel_config);
        else {
-               fwrite((char *) &config, sizeof(struct config), 1, cfp);
+               rv = fwrite((char *) &config, sizeof(struct config), 1, cfp);
+               if (rv == -1)
+                       syslog(LOG_EMERG, "Failed to write: %s [%s]\n", 
+                              file_citadel_config, strerror(errno));
                fclose(cfp);
        }
 }