summary refs log tree commit diff
path: root/conf.c
diff options
context:
space:
mode:
authorokan <okan>2008-06-14 21:51:00 +0000
committerokan <okan>2008-06-14 21:51:00 +0000
commit9d9c61b8f6cd0bdf57c925a27de584e697743981 (patch)
tree560b9913eff46d2f4a70b11bf7a2ecd9f80805dc /conf.c
parentbdcbbe7f53ce140df98f06a31dfe5cb19a40d708 (diff)
downloadcwm-9d9c61b8f6cd0bdf57c925a27de584e697743981.tar.gz
cwm-9d9c61b8f6cd0bdf57c925a27de584e697743981.tar.xz
cwm-9d9c61b8f6cd0bdf57c925a27de584e697743981.zip
slightly alter the semantics of config files:
 - if no config file, continue silently and apply defaults
 - if config file, parse and move on
 - if config file specified but not found, error out

ok oga@
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/conf.c b/conf.c
index ea22d59..8b43668 100644
--- a/conf.c
+++ b/conf.c
@@ -168,6 +168,8 @@ conf_init(struct conf *c)
 void
 conf_setup(struct conf *c, const char *conf_file)
 {
+	struct stat sb;
+
 	if (conf_file == NULL) {
 		char *home = getenv("HOME");
 
@@ -177,7 +179,11 @@ conf_setup(struct conf *c, const char *conf_file)
 		snprintf(c->conf_path, sizeof(c->conf_path), "%s/%s", home,
 		    CONFFILE);
 	} else
-		snprintf(c->conf_path, sizeof(c->conf_path), "%s", conf_file);
+		if (stat(conf_file, &sb) == -1 || !(sb.st_mode & S_IFREG))
+			errx(1, "%s: %s", conf_file, strerror(errno));
+		else
+			snprintf(c->conf_path, sizeof(c->conf_path), "%s",
+			    conf_file);
 
 	conf_init(c);