Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int CompileProgram(Program *prog) {
- int makefile = CheckExists("Makefile");
- int pid;
- if (!(pid = fork())) {
- char **argBlock;
- if (makefile) {
- argBlock = calloc(2, sizeof(char *));
- CHECK_MALLOC(argBlock);
- argBlock[0] = "/usr/bin/make";
- argBlock[1] = prog->executableName;
- } else {
- argBlock = calloc(1 + prog->sourceFiles->length + 2, sizeof(char *));
- CHECK_MALLOC(argBlock);
- argBlock[0] = "/usr/bin/gcc";
- argBlock[1] = "-o";
- argBlock[2] = prog->executableName;
- int i = 3;
- ListNode *argNode;
- Argument *arg = NULL;
- LIST_FOR(prog->sourceFiles, argNode, Argument, arg) {
- argBlock[i++] = arg->value;
- }
- assert(i == 1 + prog->sourceFiles->length + 2);
- }
- printf("%s\n", *argBlock);
- execv(*argBlock, argBlock);
- if (errno == EFAULT) {
- printf("efault\n");
- }
- perror("Failed to exec");
- exit(1);
- } else {
- // Parent
- if (pid == -1) {
- perror("Failed to fork");
- exit(EXIT_SYSCALL);
- }
- int status;
- wait(&status);
- // TODO
- }
- return 1;
- }
- ---
- /usr/bin/make
- efault
- Failed to exec: Bad address
- /usr/bin/make
- efault
- Failed to exec: Bad address
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement