]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
get config stream return value
authorBastian Dehn <hhaalo@arcor.de>
Sun, 3 Mar 2024 08:45:36 +0000 (09:45 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 3 Mar 2024 08:45:36 +0000 (09:45 +0100)
src/kds_s2000w_client.c
src/kds_s2000w_config.c
src/kds_s2000w_config.h
tools/read_config.c

index 6ca6462ccc969f23c8e83652face63e0d5cfef4f..144c314a00f0b31ef3f97902f84b0f3c0e263ad1 100644 (file)
@@ -10,8 +10,7 @@ program_config p_config;
 void _kds_s2000w_client_load_config()
 {
        const char* config_file = "/etc/sane.d/kds_s2000w_net.conf";
-       char* config_stream = NULL;
-       read_config_file(config_file, &config_stream);
+       char* config_stream = read_config_file(config_file);
        load_config(&p_config, config_stream);
 }
 
index efaa1fecf2cda2d7feb71588cc2898f9bf95c317..79c0d2454be38a2dd2380695b2809fa8cc3e67d5 100644 (file)
@@ -3,10 +3,9 @@
 #include <confuse.h>
 #include "kds_s2000w_config.h"
 
-void read_config_file(const char* filename, char** config_stream)
+char* read_config_file(const char* filename)
 {
-       free(*config_stream);
-       *config_stream = NULL;
+       char* config_stream = NULL;
 
        FILE* config_file = fopen(filename, "r");
 
@@ -17,10 +16,12 @@ void read_config_file(const char* filename, char** config_stream)
        }
        fseek(config_file, 0L, SEEK_SET);
 
-       *config_stream = malloc(sizeof(char) * char_count);
-       fread(*config_stream, char_count, 1, config_file);
+       config_stream = malloc(sizeof(char) * char_count);
+       fread(config_stream, char_count, 1, config_file);
        fclose(config_file);
        config_file = NULL;
+
+       return config_stream;
 }
 
 void load_config(program_config* config, const char* config_stream)
index 94ad4c420240221733f68b56d80f08f8008d4e20..8eadc7f922cf7d1304c03233c0b25e0e735e5e37 100644 (file)
@@ -6,6 +6,6 @@ typedef struct {
        char* username;
 } program_config;
 
-void read_config_file(const char* filename, char** config_stream);
+char* read_config_file(const char* filename);
 void load_config(program_config* config, const char* config_stream);
 #endif
\ No newline at end of file
index a2028e1049dd8fe6b9e8b9509da796b1ffae6dd3..849cbedfaf5ac7a43492a31502c7358ec1cb68a3 100644 (file)
@@ -5,10 +5,9 @@
 int main(int argc, char** argv)
 {
        program_config* config = malloc(sizeof(program_config));
-       char* config_stream = NULL;
 
        printf("config file %s\n", argv[1]);
-       read_config_file(argv[1], &config_stream);
+       char* config_stream = read_config_file(argv[1]);
        load_config(config, config_stream);
 
        printf("scanner_url: %s\n", config->scanner_url);