]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
config decleration variables first
authorBastian Dehn <hhaalo@arcor.de>
Wed, 6 Mar 2024 20:00:03 +0000 (21:00 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 6 Mar 2024 20:00:03 +0000 (21:00 +0100)
src/kds_s2000w_config.c

index 1894eb0243f3cfc22750f45740e87732b0a4e280..505b86706f0a5f89539281ce95fe16ab6929a2a5 100644 (file)
@@ -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);