Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/mman.h>
- #include <string.h>
- #include <sys/wait.h>
- #define ER(number) { \
- printf("E%d\n", number); \
- exit(-1); \
- }
- #define MAXLEN 5000
- int main() {
- umask(0000);
- int fd = creat("program.c", 0666);
- if (fd < 0) ER(1);
- char* init = "#include <stdio.h>\n int main() { printf(\"%d\\n\", (";
- size_t initlen = strlen(init);
- if (write(fd, init, initlen) != initlen) ER(2);
- char input[MAXLEN];
- fgets(input, MAXLEN, stdin);
- size_t inputlen = strlen(input);
- if (write(fd, input, inputlen) != inputlen) ER(3);
- char* fin = ")); return 0; }";
- size_t finlen = strlen(fin);
- if (write(fd, fin, finlen) != finlen) ER(4);
- if (close(fd) < 0) ER(45);
- int res = fork();
- if (res > 0) {
- int* wstatus;
- wait(wstatus);
- int res1 = fork();
- if (res1 > 0) {
- int* wstatus1;
- wait(wstatus1);
- if (unlink("program.out") < 0) ER(46);
- if (unlink("program.c") < 0) ER(47);
- }
- else if (res1 == 0) {
- execlp("./program.out", "./program.out", 0);
- ER(5);
- }
- else if (res1 < 0) ER(6);
- }
- else if (res == 0) {
- execlp("gcc", "gcc", "program.c", "-o", "program.out", 0);
- ER(9);
- }
- else if (res < 0) ER(10);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement