#include #include #include "config.h" enum ConfigError config_load( const char *root_dir, const char *target, struct Config **config ) { if (root_dir == 0) { return ENV_SPEC_ROOT_DIR_MISSING; } if (root_dir[0] == 0) { return ENV_SPEC_ROOT_DIR_EMPTY; } if (target == 0) { return INVALID_TARGET; } size_t target_len = strlen(target); if (target_len == 0) { return INVALID_TARGET; } *config = malloc(sizeof(struct Config)); (*config)->root_dir = root_dir; char *copy_target = calloc(1, target_len + 1); strcpy(copy_target, target); (*config)->target = copy_target; return 0; } void config_free(struct Config *config) { if (!config) { return; } free((void *)config->target); free(config); }