error.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * File: error.h
  3. * Author: Arthur Brandao
  4. *
  5. * Created on 8 novembre 2018
  6. */
  7. #ifndef ERROR_H
  8. #define ERROR_H
  9. #include <stdio.h>
  10. /* --- Macro --- */
  11. #define serror(str) fprintf(stderr, str" : %s\n", serrlib[serrno])
  12. #define strserror(index) serrlib[index]
  13. #define adderror(str) fprintf(stderr, "Erreur dans le fichier "__FILE__" ligne %d, "str"\n", __LINE__)
  14. #define addperror(str) fprintf(stderr, "Erreur dans le fichier "__FILE__" ligne %d, ", __LINE__); perror(str" ")
  15. #define addserror(str) fprintf(stderr, "Erreur dans le fichier "__FILE__" ligne %d, "str" : %s\n", __LINE__, strserror(serrno))
  16. /* --- Constantes Generales --- */
  17. #define ERR -1
  18. #define FAIL 0
  19. #define SUCCESS 1
  20. /* --- Constantes Erreurs --- */
  21. #define SEBADEND 1
  22. #define SEBADET 2
  23. #define SEOPENF 3
  24. #define SEREDIRTYPE 4
  25. #define SEBADREDIR 5
  26. #define SEBADCMD 6
  27. #define SEWC 7
  28. #define SEADDWC 8
  29. /* --- Extern --- */
  30. extern int errno;
  31. extern int serrno; //Shell Errno
  32. extern char* serrlib[];
  33. /* --- Fonctions --- */
  34. /**
  35. * Change un fd par la valeur d'un autre fd
  36. * @param int fd accueil
  37. * @param int fd source
  38. * @return int Le nouveau fd du fichier qui avait le fd d'accueil
  39. */
  40. int redirect_fd(int, int);
  41. #endif /* ERROR_H */