From 3f21e7afbc283f4c7f1365dda3bce99c67c38932 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Fri, 14 Feb 2025 17:53:29 +0100 Subject: [PATCH] change read config file seek size --- src/kds_s2000w_config.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/kds_s2000w_config.c b/src/kds_s2000w_config.c index a16e311..5d24782 100644 --- a/src/kds_s2000w_config.c +++ b/src/kds_s2000w_config.c @@ -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); -- 2.39.5