char* kds_s2000w_config_read(const char* filename)
{
FILE* config_file = fopen(filename, "r");
- char* buf = malloc(sizeof(char));
- char** mem = malloc(sizeof(char*));
- size_t* sizeloc = malloc(sizeof(size_t));
- FILE* config_stream = open_memstream(mem, sizeloc);
+ size_t config_size = 0;
- while (fread(buf, sizeof(char), 1, config_file) > 0) {
- fwrite(buf, sizeof(char), 1, config_stream);
+ char buf = 0;
+ while (fread(&buf, sizeof(char), 1, config_file) > 0) {
+ config_size++;
}
+ fseek(config_file, 0, SEEK_SET);
+
+ char* config_string = malloc(sizeof(char) * config_size + 1);
+ fread(config_string, config_size, 1, config_file);
+ config_string[config_size] = '\0';
fclose(config_file);
config_file = NULL;
- fclose(config_stream);
- config_stream = NULL;
-
- char* config_string = *mem;
-
- free(buf);
- buf = NULL;
- free(sizeloc);
- sizeloc = NULL;
- free(mem);
- mem = NULL;
return config_string;
}