2023-11-22 21:39:27 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2023-11-23 14:40:17 +00:00
|
|
|
enum ConfigError config_load(
|
2023-11-23 15:07:22 +00:00
|
|
|
const char *cwd,
|
2023-11-23 11:09:32 +00:00
|
|
|
const char *root_dir,
|
|
|
|
const char *target,
|
2023-11-23 14:40:17 +00:00
|
|
|
struct Config **config
|
2023-11-23 11:09:32 +00:00
|
|
|
) {
|
2023-11-23 15:07:22 +00:00
|
|
|
if (cwd == 0) {
|
|
|
|
return CE_ENV_CWD_INVALID;
|
2023-11-22 21:39:27 +00:00
|
|
|
}
|
2023-11-23 15:07:22 +00:00
|
|
|
if (root_dir == 0) {
|
|
|
|
return CE_ENV_SPEC_ROOT_DIR_INVALID;
|
2023-11-22 21:39:27 +00:00
|
|
|
}
|
|
|
|
if (target == 0) {
|
2023-11-23 15:07:22 +00:00
|
|
|
return CE_TARGET_INVALID;
|
2023-11-22 21:39:27 +00:00
|
|
|
}
|
|
|
|
|
2023-11-23 14:40:17 +00:00
|
|
|
*config = malloc(sizeof(struct Config));
|
2023-11-23 15:07:22 +00:00
|
|
|
(*config)->cwd = cwd;
|
2023-11-23 14:40:17 +00:00
|
|
|
(*config)->root_dir = root_dir;
|
2023-11-23 15:07:22 +00:00
|
|
|
(*config)->target = target;
|
2023-11-22 21:39:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-11-23 14:40:17 +00:00
|
|
|
void config_free(struct Config *config) {
|
2023-11-22 21:39:27 +00:00
|
|
|
if (!config) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(config);
|
|
|
|
}
|