diff options
author | okan | 2008-06-14 21:51:00 +0000 |
---|---|---|
committer | okan | 2008-06-14 21:51:00 +0000 |
commit | 1828cb75bd4052187e7a3640de9c0060b54b210d (patch) | |
tree | ebb171a56675be2169e7ccb0321ac58985685da4 /conf.c | |
parent | c13dbbd835133e5160bdeefa8251adef63c56a9e (diff) | |
download | cwm-1828cb75bd4052187e7a3640de9c0060b54b210d.tar.gz |
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 '')
-rw-r--r-- | conf.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $Id: conf.c,v 1.37 2008/06/14 21:48:54 okan Exp $ + * $Id: conf.c,v 1.38 2008/06/14 21:51:00 okan Exp $ */ #include "headers.h" @@ -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); |