diff options
| -rw-r--r-- | src/config.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/config.c b/src/config.c index 083150e..b22588e 100644 --- a/src/config.c +++ b/src/config.c @@ -10,11 +10,10 @@ #define CONFIG_STR_SIZE 128 -static struct uconfig_s *uconfig; static char *ftag_config_keys[FC_COUNT]; static char ftag_config_values[FC_COUNT][CONFIG_STR_SIZE]; -static void ftag_config_read(enum ftag_config_e key) +static void ftag_config_read(struct uconfig_s *uconfig, enum ftag_config_e key) { char *new_value = uconfig_get(uconfig, ftag_config_keys[key]); if (new_value != NULL) { @@ -25,6 +24,8 @@ static void ftag_config_read(enum ftag_config_e key) static int ftag_config_load_file(const char *config_file) { + struct uconfig_s *uconfig; + if (!(config_file && file_exists(config_file))) return 0; @@ -36,8 +37,9 @@ static int ftag_config_load_file(const char *config_file) exit(EXIT_FAILURE); } for (enum ftag_config_e key = FC_FIRST; key < FC_COUNT; key++) { - ftag_config_read(key); + ftag_config_read(uconfig, key); } + uconfig_destroy(uconfig); return 1; } @@ -74,13 +76,6 @@ void ftag_config_init(const char *opt_config_file) strcpy(ftag_config_values[FC_REMOTE_HOST], "localhost"); strcpy(ftag_config_values[FC_REMOTE_ROOT], "ftag"); - uconfig = NULL; - int config_loaded = 0; - - config_loaded = ftag_config_load_file(config_file); - if (config_loaded) - return; - ftag_config_load_file(config_file); } @@ -91,6 +86,4 @@ const char *ftag_config_get(enum ftag_config_e key) void ftag_config_finalize(void) { - if (uconfig) - uconfig_destroy(uconfig); } |
