From 22f5cb71af029deb1c919b7c6bc958572f8da9f9 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 7 Jun 2010 21:45:33 -0700 Subject: [PATCH] gui: Create user settings directory if it doesn't already exist. 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 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ui/gui/psppire-conf.c b/src/ui/gui/psppire-conf.c index 07db3b58..dbcdf0e0 100644 --- a/src/ui/gui/psppire-conf.c +++ b/src/ui/gui/psppire-conf.c @@ -20,7 +20,9 @@ */ #include +#include #include +#include #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"); -- 2.30.2