correction code

This commit is contained in:
2026-04-17 17:28:11 +02:00
parent 53548f9159
commit b74419747b
5 changed files with 30 additions and 15 deletions
+15 -5
View File
@@ -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);