From d3de84f798759890958141c29d2c783201c1da18 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Wed, 6 Mar 2024 21:00:03 +0100 Subject: [PATCH] config decleration variables first --- src/kds_s2000w_config.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/kds_s2000w_config.c b/src/kds_s2000w_config.c index 1894eb0..505b867 100644 --- a/src/kds_s2000w_config.c +++ b/src/kds_s2000w_config.c @@ -5,10 +5,14 @@ char* read_config_file(const char* filename) { - FILE* config_file = fopen(filename, "r"); - + FILE* config_file = NULL; + char* buf = NULL; + char* config_stream = NULL; int char_count = 0; - char* buf = malloc(sizeof(char)); + + config_file = fopen(filename, "r"); + + buf = malloc(sizeof(char)); while(fread(buf, sizeof(char), 1, config_file)) { char_count++; } @@ -16,7 +20,7 @@ char* read_config_file(const char* filename) buf = NULL; fseek(config_file, 0L, SEEK_SET); - char* config_stream = malloc(sizeof(char) * char_count); + config_stream = malloc(sizeof(char) * char_count); fread(config_stream, char_count, 1, config_file); config_stream[char_count - 1 ] = '\0'; fclose(config_file); @@ -30,6 +34,11 @@ void load_config(program_config* config, const char* config_stream) config->scanner_url = NULL; config->username = NULL; + cfg_t* cfg = NULL; + char* value_str = NULL; + size_t str_length = 0; + int status = 0; + if (strlen(config_stream) <= 0) { return; } @@ -40,12 +49,12 @@ void load_config(program_config* config, const char* config_stream) CFG_END() }; - cfg_t* cfg = cfg_init(opts, 0); + cfg = cfg_init(opts, 0); - int status = cfg_parse_buf(cfg, config_stream); + status = cfg_parse_buf(cfg, config_stream); - char* value_str = cfg_getstr(cfg, "scanner_url"); - size_t str_length = strlen(value_str) + 1; + value_str = cfg_getstr(cfg, "scanner_url"); + str_length = strlen(value_str) + 1; config->scanner_url = malloc(sizeof(char) * str_length); memcpy(config->scanner_url, value_str, str_length); -- 2.39.5