Refactor ifdef logic in config to r/a+ modes.
This commit is contained in:
parent
88e02be97a
commit
d038cdce37
|
@ -43,12 +43,6 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RARCH_CONSOLE
|
|
||||||
#define CREATE_FILE_IF_NOT_EXISTS 1
|
|
||||||
#else
|
|
||||||
#define CREATE_FILE_IF_NOT_EXISTS 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAX_INCLUDE_DEPTH 16
|
#define MAX_INCLUDE_DEPTH 16
|
||||||
|
|
||||||
struct entry_list
|
struct entry_list
|
||||||
|
@ -75,7 +69,7 @@ struct config_file
|
||||||
struct include_list *includes;
|
struct include_list *includes;
|
||||||
};
|
};
|
||||||
|
|
||||||
static config_file_t *config_file_new_internal(const char *path, unsigned depth, unsigned create_if_not_exists);
|
static config_file_t *config_file_new_internal(const char *path, unsigned depth);
|
||||||
|
|
||||||
static char *getaline(FILE *file)
|
static char *getaline(FILE *file)
|
||||||
{
|
{
|
||||||
|
@ -255,7 +249,7 @@ static void add_sub_conf(config_file_t *conf, char *line)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
config_file_t *sub_conf = config_file_new_internal(real_path, conf->include_depth + 1, CREATE_FILE_IF_NOT_EXISTS);
|
config_file_t *sub_conf = config_file_new_internal(real_path, conf->include_depth + 1);
|
||||||
if (!sub_conf)
|
if (!sub_conf)
|
||||||
{
|
{
|
||||||
free(path);
|
free(path);
|
||||||
|
@ -320,7 +314,7 @@ static bool parse_line(config_file_t *conf, struct entry_list *list, char *line)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static config_file_t *config_file_new_internal(const char *path, unsigned depth, unsigned create_if_not_exists)
|
static config_file_t *config_file_new_internal(const char *path, unsigned depth)
|
||||||
{
|
{
|
||||||
struct config_file *conf = (struct config_file*)calloc(1, sizeof(*conf));
|
struct config_file *conf = (struct config_file*)calloc(1, sizeof(*conf));
|
||||||
if (!conf)
|
if (!conf)
|
||||||
|
@ -338,16 +332,14 @@ static config_file_t *config_file_new_internal(const char *path, unsigned depth,
|
||||||
|
|
||||||
conf->include_depth = depth;
|
conf->include_depth = depth;
|
||||||
|
|
||||||
|
#ifdef RARCH_CONSOLE
|
||||||
|
// This will create the file if it doesn't exist, and start reading at beginning.
|
||||||
|
FILE *file = fopen(path, "a+");
|
||||||
|
#else
|
||||||
FILE *file = fopen(path, "r");
|
FILE *file = fopen(path, "r");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!file && create_if_not_exists)
|
if (!file)
|
||||||
{
|
|
||||||
file = fopen(path, "w");
|
|
||||||
fclose(file);
|
|
||||||
file = fopen(path, "r"); // try again to open
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!file)
|
|
||||||
{
|
{
|
||||||
free(conf->path);
|
free(conf->path);
|
||||||
free(conf);
|
free(conf);
|
||||||
|
@ -388,7 +380,7 @@ static config_file_t *config_file_new_internal(const char *path, unsigned depth,
|
||||||
|
|
||||||
config_file_t *config_file_new(const char *path)
|
config_file_t *config_file_new(const char *path)
|
||||||
{
|
{
|
||||||
return config_file_new_internal(path, 0, CREATE_FILE_IF_NOT_EXISTS);
|
return config_file_new_internal(path, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_file_free(config_file_t *conf)
|
void config_file_free(config_file_t *conf)
|
||||||
|
|
Loading…
Reference in New Issue