-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplatform_linux.c
53 lines (46 loc) · 1.28 KB
/
platform_linux.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
53
#define PlatformDefaultTarget Config_TARGET_LINUX
void
platformPathAtBinary(char* path, sz size) {
char tmp[PATH_MAX] = Zero;
tmp[0] = '/';
strncat(tmp, path, PATH_MAX);
readlink("/proc/self/exe", path, size);
char* last_slash = path;
for (char* iter = path; *iter != '\0'; iter++) {
if (*iter == '/') {
last_slash = iter;
}
}
if (*last_slash == '/') {
*last_slash = '\0';
}
strncat(path, tmp, size);
}
ErrorCode
platformAssemble(char* nasm_path, char* asm_file) {
ErrorCode ret = Ok;
char* nasm_args[] = { nasm_path, "-Znasm_output", "-f", "elf64", asm_file };
if (Ok == platformRunProcess(nasm_args, ArrayCount(nasm_args), 0)) {
}
else {
fprintf(stderr, "nasm failed\n");
ret = CouldNotAssemble;
}
return ret;
}
ErrorCode
platformLink(char* ld_path, char* filename_without_extension) {
ErrorCode ret = Ok;
printf("Running ld\n");
char obj_file[PathMax] = {0}; {
snprintf(obj_file, PathMax, "%s.o", filename_without_extension);
}
char* ld_args[] = { ld_path, "-arch", "x86_64", obj_file, "-o", filename_without_extension };
if (Ok == platformRunProcess(ld_args, ArrayCount(ld_args), 0)) {
}
else {
fprintf(stderr, "ld failed\n");
ret = CouldNotLink;
}
return ret;
}