/
env.c
53 lines (44 loc) · 1.09 KB
/
env.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "env.h"
#include "slice.h"
static char env_name[] = "CPKGROOT";
struct list_head env_list;
#define PACKAGE_ENV_LISTLEN 512
int env_init() {
int len, i;
struct env *env;
char *res[PACKAGE_ENV_LISTLEN];
char *env_value = getenv(env_name);
INIT_LIST_HEAD(&env_list);
if (!env_value)
return 0;
len = strsplit(env_value, ";", res, PACKAGE_ENV_LISTLEN);
for (i = 0; i < len; i++) {
env = malloc(sizeof(*env));
if (!env)
continue;
env_make(env, res[i]);
INIT_LIST_HEAD(&env->allpackages);
list_add(&env->alllink, &env_list);
free(res[i]);
pkg_makeroot(env);
}
return 0;
}
int env_make(struct env *ev, const char *path) {
if (strlen(path) >= PACKAGE_PATH_LEN) {
fprintf(stderr, "env init failed: %s\n", path);
return -1;
}
sprintf(ev->objpath, "%s/obj/", path);
sprintf(ev->srcpath, "%s/src/", path);
sprintf(ev->libpath, "%s/pkg/", path);
sprintf(ev->includepath, "%s/include/", path);
return 0;
}
int env_check(struct env *ev, const char *path) {
return strprefix(path, ev->srcpath);
}