value->value[value->value_length] = '\0';
}
-void read_config_file(const char* filename, char* config_stream)
+void read_config_file(const char* filename, char** config_stream)
{
+ free(*config_stream);
+ *config_stream = NULL;
+
FILE* config_file = fopen(filename, "r");
int char_count = 0;
char* buf = malloc(sizeof(char));
- while(fread(buf, 1, 1, config_file) != 0) {
+ while(fread(buf, sizeof(char), 1, config_file)) {
char_count++;
}
- rewind(config_file);
+ fseek(config_file, 0L, SEEK_SET);
- config_stream = malloc(sizeof(char) * char_count);
- fread(config_stream, sizeof(char), char_count, config_file);
+ *config_stream = malloc(sizeof(char) * char_count);
+ fread(*config_stream, char_count, 1, config_file);
fclose(config_file);
+ config_file = NULL;
}
void load_config(program_config* config, const char* config_stream)
char* username;
} program_config;
-void read_config_file(const char* filename, char* config_stream);
+void read_config_file(const char* filename, char** config_stream);
void load_config(program_config* config, const char* config_stream);
#endif
\ No newline at end of file
program_config* config = malloc(sizeof(program_config));
char* config_stream = NULL;
- read_config_file(argv[1], config_stream);
+ read_config_file(argv[1], &config_stream);
+ printf("config:\n%s\n", config_stream);
+ load_config(config, config_stream);
+
+ printf("scanner_url: %s", config->scanner_url);
+ printf("username %s", config->username);
free(config_stream);
config_stream = NULL;
+ free(config->scanner_url);
+ config->scanner_url = NULL;
+ free(config->username);
+ config->username = NULL;
+ free(config);
+ config = NULL;
return 0;
}
\ No newline at end of file