]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change read config file seek size
authorBastian Dehn <hhaalo@arcor.de>
Fri, 14 Feb 2025 16:53:29 +0000 (17:53 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 14 Feb 2025 16:53:29 +0000 (17:53 +0100)
src/kds_s2000w_config.c

index a16e311c6d27b24b036af0ec3ec93c7d049769f0..5d24782bdfb5b5da621e81eed7024e38f5ab6e14 100644 (file)
@@ -18,13 +18,9 @@ void _kds_s2000w_config_copy_string_to_config_value(cfg_t* cfg, const char* key,
 char* kds_s2000w_config_read(const char* filename)
 {
        FILE* config_file = fopen(filename, "r");
-       size_t config_size = 0;
-
-       char buf = 0;
-       while (fread(&buf, sizeof(char), 1, config_file) > 0) {
-               config_size++;
-       }
-       fseek(config_file, 0, SEEK_SET);
+       fseek(config_file, 0, SEEK_END);
+       size_t config_size = ftell(config_file);
+       rewind(config_file);
 
        char* config_string = malloc(sizeof(char) * config_size + 1);
        fread(config_string, config_size, 1, config_file);