diff --git a/wmbutton/wmb_libs.c b/wmbutton/wmb_libs.c index 55802ff..e778743 100644 --- a/wmbutton/wmb_libs.c +++ b/wmbutton/wmb_libs.c @@ -191,6 +191,23 @@ void RunAppN(int app) } /***********************************************************************/ +/*********************************************************************** + * canOpenFile(const char *path) + * + * Check if the file at a given path can be opened. + ***********************************************************************/ +int canOpenFile(const char *path) +{ + FILE *fp; + + if ((fp = fopen(path, "r")) == NULL) + return 0; + else { + fclose(fp); + return 1; + } +} + /*********************************************************************** * Parse(int app) * diff --git a/wmbutton/wmbutton.c b/wmbutton/wmbutton.c index 7b061b0..6d4dd26 100644 --- a/wmbutton/wmbutton.c +++ b/wmbutton/wmbutton.c @@ -111,6 +111,14 @@ int main(int argc, char **argv) /* Parse Command Line Arguments */ parseargs(argc, argv); + /* Catch fire if no configuration file exists */ + if (!canOpenFile(Config.configfile)) { + if(!canOpenFile(CONFIGGLOBAL)) { + err_mess(FAILCONF, Config.configfile); + return (1); + } + } + /* Open Display */ if ((display = XOpenDisplay(Config.Display_str)) == NULL) err_mess(FAILDISP, Config.Display_str); diff --git a/wmbutton/wmbutton.h b/wmbutton/wmbutton.h index b653e7d..4cd3a68 100644 --- a/wmbutton/wmbutton.h +++ b/wmbutton/wmbutton.h @@ -84,6 +84,7 @@ void parseargs(int argc, char **argv); char *readln(FILE *fp); /* read line from file, return pointer to it */ void err_mess(int err, char *str); /* Error Handling Routine */ void show_usage(void); /* show usage message to stderr */ +int canOpenFile(const char *path); int flush_expose(Window w);