fix segfault when config.emk does not exist
This commit is contained in:
parent
2a579f070e
commit
8dcce562cd
13
src/parse.c
13
src/parse.c
@ -26,6 +26,12 @@
|
||||
|
||||
#include "parse.h"
|
||||
|
||||
/* Variable indicating whether config.emk exists
|
||||
* 1 means config.emk exists
|
||||
* 0 means config.emk does not exist
|
||||
*/
|
||||
int emkConfigExists;
|
||||
|
||||
struct emkfileData {
|
||||
char cc;
|
||||
char prefix;
|
||||
@ -60,6 +66,7 @@ char checkForFiles() {
|
||||
printf(COL_YELLOW "WRN" COL_RESET " | use a config.emk file, rather\n");
|
||||
printf(COL_YELLOW "WRN" COL_RESET " | than embedding settings directly\n");
|
||||
printf(COL_YELLOW "WRN" COL_RESET " | within the emkfile.\n");
|
||||
emkConfigExists = 1;
|
||||
} else if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
printf(COL_BLUE "INF" COL_RESET " | using config.emk at %s/config.emk\n", cwd);
|
||||
}
|
||||
@ -85,8 +92,10 @@ char includeConfig() {
|
||||
FILE *emkconfig, *emkfile, *emkfile_new;
|
||||
char filename[100], contents;
|
||||
|
||||
if (emkConfigExists == 1) {
|
||||
printf(COL_BLUE "INF" COL_RESET " | parsing config.emk\n");
|
||||
emkconfig = fopen(EMKCONFIG, "r");
|
||||
}
|
||||
printf(COL_BLUE "INF" COL_RESET " | parsing emkfile\n");
|
||||
emkfile = fopen(EMKFILE, "r");
|
||||
|
||||
@ -95,11 +104,13 @@ char includeConfig() {
|
||||
|
||||
printf(COL_BLUE "INF" COL_RESET " | running preprocessing tasks...\n");
|
||||
/* write emkconfig to new emkfile */
|
||||
if (emkConfigExists == 1) {
|
||||
contents = fgetc(emkconfig);
|
||||
while (contents != EOF) {
|
||||
fputc(contents, emkfile_new);
|
||||
contents = fgetc(emkconfig);
|
||||
}
|
||||
}
|
||||
|
||||
/* write emkfile to new emkfile */
|
||||
contents = fgetc(emkfile);
|
||||
@ -109,7 +120,9 @@ char includeConfig() {
|
||||
}
|
||||
|
||||
printf(COL_BLUE "INF" COL_RESET " | closing files\n");
|
||||
if (emkConfigExists == 1) {
|
||||
fclose(emkconfig);
|
||||
}
|
||||
fclose(emkfile);
|
||||
fclose(emkfile_new);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user