-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinker_d.d
61 lines (54 loc) · 1.29 KB
/
linker_d.d
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
53
54
55
56
57
58
59
60
import core.sys.posix.unistd;
import core.sys.posix.stdlib;
import core.sys.posix.stdio;
import core.sys.posix.sys.wait;
extern(C) {
extern __gshared char **environ;
}
enum POLLEN_LIBRARY_SEARCH_PATH = "";
@safe
int WTERMSIG(int status)
{
return ((status) & 0x7f);
}
@safe
int WIFEXITED(int status)
{
return (WTERMSIG(status) == 0);
}
@safe
int WEXITSTATUS(int status)
{
return (((status) & 0xff00) >> 8);
}
int link_file(string filename, string outputname)
{
string pollenrt0 = "pollenrt0.o";
assert(filename != null);
assert(outputname != null);
pid_t pid = fork();
if (pid == -1) {
perror("fork");
exit(EXIT_FAILURE);
} else if (pid == 0) {
const(char *)[9] args = ["cc",
"-L", POLLEN_LIBRARY_SEARCH_PATH,
pollenrt0.ptr, filename.ptr, "-lpollen",
"-o", outputname.ptr, null];
if (execve("/usr/bin/cc", args.ptr, environ) == -1) {
perror("execve");
return 1;
}
} else {
int status;
if (waitpid(pid, &status, 0) == -1) {
perror("waitpid");
return 2;
}
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
fprintf(stderr, "Compilation failed\n");
return 3;
}
}
return 0;
}