gui: Create user settings directory if it doesn't already exist. 20100608040508/pspp
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 8 Jun 2010 04:45:33 +0000 (21:45 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 8 Jun 2010 04:45:33 +0000 (21:45 -0700)
The user settings directory doesn't necessarily exist.  Some program has to
create it, and PSPPIRE might be the first program that wants it, so it
should try to create it.

Discovered on OpenBSD.

src/ui/gui/psppire-conf.c

index 07db3b58c21e5d07e16d8789a285f2ad20978450..dbcdf0e01f08d94907fedab3e43486e2a874c812 100644 (file)
@@ -20,7 +20,9 @@
 */
 
 #include <config.h>
+#include <errno.h>
 #include <stdio.h>
+#include <sys/stat.h>
 
 #include "psppire-conf.h"
 
@@ -140,7 +142,15 @@ psppire_conf_class_init (PsppireConfClass *class)
 static void
 psppire_conf_init (PsppireConf *conf)
 {
-  const gchar *dirname = g_get_user_config_dir ();
+  const gchar *dirname;
+  struct stat s;
+
+  /* Get the name of the directory for user configuration files, then, if it
+     doesn't already exist, create it, since we might be the first program
+     to want to put files there. */
+  dirname = g_get_user_config_dir ();
+  if (stat (dirname, &s) == -1 && errno == ENOENT)
+    mkdir (dirname, 0777);
 
   conf->filename = g_strdup_printf ("%s/%s", dirname, "psppirerc");