chiark / gitweb /
lib/home.c: Introduce functions for building pathmames in home directories.
[disorder] / disobedience / settings.c
index 2c4ffeb3c32f2d2e50e680e8d28ce8e03579918c..18af6c1c8e590cc78593bacfeeab0e09ed29f09d 100644 (file)
@@ -150,11 +150,15 @@ void init_styles(void) {
 }
 
 void save_settings(void) {
 }
 
 void save_settings(void) {
-  char *dir, *path, *tmp;
+  const char *dir;
+  char *path, *tmp;
   FILE *fp = 0;
   size_t n, m, c;
 
   FILE *fp = 0;
   size_t n, m, c;
 
-  byte_xasprintf(&dir, "%s/.disorder", getenv("HOME"));
+  if(!(dir = profile_directory())) {
+    fpopup_msg(GTK_MESSAGE_ERROR, "failed to find home directory");
+    goto done;
+  }
   byte_xasprintf(&path, "%s/disobedience", dir);
   byte_xasprintf(&tmp, "%s.tmp", path);
   mkdir(dir, 02700);                    /* make sure directory exists */
   byte_xasprintf(&path, "%s/disobedience", dir);
   byte_xasprintf(&tmp, "%s.tmp", path);
   mkdir(dir, 02700);                    /* make sure directory exists */
@@ -206,8 +210,9 @@ void load_settings(void) {
   int nvec;
   size_t n, m, c;
 
   int nvec;
   size_t n, m, c;
 
-  byte_xasprintf(&path, "%s/.disorder/disobedience", getenv("HOME"));
-  if(!(fp = fopen(path, "r"))) {
+  if(!(path = profile_filename("disobedience")))
+    fpopup_msg(GTK_MESSAGE_ERROR, "failed to find home directory");
+  else if(!(fp = fopen(path, "r"))) {
     if(errno != ENOENT)
       fpopup_msg(GTK_MESSAGE_ERROR, "error opening %s: %s",
                  path, strerror(errno));
     if(errno != ENOENT)
       fpopup_msg(GTK_MESSAGE_ERROR, "error opening %s: %s",
                  path, strerror(errno));