From: Bastian Dehn Date: Wed, 6 Mar 2024 20:00:03 +0000 (+0100) Subject: config decleration variables first X-Git-Tag: v1.0.0^2~135 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=d3de84f798759890958141c29d2c783201c1da18;p=sane-kds-s2000w-net.git config decleration variables first --- 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);