123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /*
- * File: error.c
- * Author: Arthur Brandao
- *
- * Created on 8 novembre 2018
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include "error.h"
- /* --- Extern --- */
- int serrno = 0;
- char* serrlib[] = {
- "Reussite",
- "Ligne de commande mal terminée",
- "& inattendue",
- "Impossible d'ouvrir/créer le fichier pour la redirection",
- "Type de redirection incorrect",
- "Redirection Incorrect",
- "Command incorrect",
- "Analyse wildcard impossible",
- "Echec ajout wildcard dans argv"
- };
- /* --- Fonctions publiques --- */
- int redirect_fd(int fd1, int fd2){
- int tmpfd;
- //On duplique le 1er fd
- tmpfd = dup(fd1);
- if(tmpfd == ERR){
- addperror("Erreur pendant la duplication");
- return ERR;
- }
- //On fait en sorte que fd1 soit lié au fichier de fd2
- if(dup2(fd2, fd1) == ERR){
- addperror("Erreur pendant le changement de fd");
- return ERR;
- }
- //On ferme l'ancien fd2
- if(close(fd2) == ERR){
- addperror("Erreur pendant la fermeture de fd2");
- return ERR;
- }
- //On retourne le nouveau fd de fd1
- return tmpfd;
- }
|