correction code
This commit is contained in:
@@ -25,19 +25,29 @@ int duper(char **argv, char *output){
|
||||
int wstatus;
|
||||
pid_t pid = fork();
|
||||
|
||||
if(pid < 0) return 1;
|
||||
if(pid < 0) {
|
||||
|
||||
printf("Something went wrong in duper.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Child
|
||||
else if (pid == 0){
|
||||
|
||||
// ouverture en mode write
|
||||
FILE *file = fopen(output, "w");
|
||||
if(!file) exit(-1);
|
||||
|
||||
if(!file) {
|
||||
printf("Something went wrong in duper.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int fno = fileno(file);
|
||||
if(dup2(fno, STDOUT_FILENO) == -1) exit(-1);
|
||||
|
||||
if(dup2(fno, STDOUT_FILENO) == -1){
|
||||
|
||||
printf("Something went wrong in duper.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
execvp(argv[0],argv);
|
||||
|
||||
Reference in New Issue
Block a user