/***************************************
*                                      *
*   Copyright (c) 2002 Jean-Eric Pin   *
*   All rights reserved.               *
*                                      *
*   TAB = 2 spaces                     *
*                                      *
***************************************/

/*-------------------------------------------------------------------
 * Erreurs.c    Jean-Eric Pin 27/12/2002
 *-------------------------------------------------------------------
 */     

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include "Erreurs.h"
#include "Main.h"

void Erreur_fopen(int erreur)
{
#if SYSTEME == UNIX
  switch (erreur)
  {
    case EACCES : 
      printf("Search permission is denied on a component of the path prefix, or the file exists and the permissions specified by mode are denied, or the file does not exist and write permission is denied for the parent directory of the file to be created.\n");
    break;

    case EINTR : 
      printf("A signal was caught during fopen().\n");
    break;
 
    case EISDIR : 
      printf("The named file is a directory and mode requires write access.\n");
    break;

    case ELOOP : 
      printf("Too many symbolic links were encountered in resolving path.\n");
    break;
 
    case EMFILE : 
      printf("{OPEN_MAX} or {STREAM_MAX} file descriptors are currently open in the calling process.\n"); 
    break;

    case ENAMETOOLONG : 
      printf("The length of the filename exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.\n");
    break;
  
    case ENFILE : 
      printf("The maximum allowable number of files is currently open in the system.\n");
    break;
  
    case ENOENT : 
      printf("A component of filename does not name an existing file or filename is an empty string.\n");
    break;
  
    case ENOSPC : 
      printf("The directory or file system that would contain the new file cannot be expanded, the file does not exist, and it was to be created.\n");
    break;
  
    case ENOTDIR : 
      printf("A component of the path prefix is not a directory.\n");
    break;
 
    case ENXIO : 
      printf("The named file is a character special or block special file, and the device associated with this special file does not exist.\n");
    break;
 
    case EOVERFLOW : 
      printf("The named file is a regular file and the size of the file cannot be represented correctly in an object of type off_t.\n");
    break;
 
    case EROFS : printf("The named file resides on a read-only file system and mode requires write access.\n");
    break;

    case EINVAL : 
      printf("The value of the mode argument is not valid.\n");
    break;
  
    case ENOMEM : 
      printf("Insufficient storage space is available\n");
    break;

    case ETXTBSY : 
      printf("The file is a pure procedure (shared text) file that is being executed and mode requires write access\n");
    break;
  }
#endif
}

void Erreur_fclose(int erreur)
{
#if SYSTEME == UNIX
  switch (erreur)
  {
    case EACCES : 
      printf("Search permission is denied on a component of the path prefix, or the file exists and the permissions specified by mode are denied, or the file does not exist and write permission is denied for the parent directory of the file to be created.\n");
    break;

    case EAGAIN :
      printf("The O_NONBLOCK flag is set for the file descriptor underlying stream, and the process would be delayed in the write operation.\n");

    case EBADF :
      printf("The file descriptor underlying stream is not valid.\n"); 

    case EINTR :
      printf("The fclose() function was interrupted by a signal.\n"); 

    case ENOSPC :
      printf("There was no free space remaining on the device containing the file.\n"); 

    case EPIPE :
      printf("An attempt was made to write to a pipe or FIFO that is not open for reading by any process. A SIGPIPE signal is also sent to the process.\n"); 
  }
#endif
}

void Erreur_printf(int erreur)
{
#if SYSTEME == UNIX
  switch (erreur)
  {
    case EAGAIN :
      printf("The O_NONBLOCK flag is set for the file descriptor underlying stream and the process would be delayed in the write operation.\n"); 

    /* 
     * case EILSEQ :
     *   printf("A wide character code that does not correspond to a valid character has been detected.\n"); 
     */

    case EINTR :
      printf("A signal interrupted the call.\n"); 

    case EIO :
      printf("A physical I/O error has occurred.\n"); 

    case EPIPE :
      printf("An attempt is made to write to a pipe or FIFO that is not open for reading by any process. A SIGPIPE signal is also sent to the thread.\n"); 

    case ENOMEM :
      printf("Insufficient storage space is available.\n"); 

    case ENXIO :
      printf("A request was made of a non-existent device, or the request was outside the capabilities of the device.\n"); 
  }
#endif
}

void Erreur_scanf(int erreur)
{
#if SYSTEME == UNIX
  switch (erreur)
  {
    case EAGAIN:
      printf("The O_NONBLOCK flag is set for the file descriptor's underlying stream and the process would be delayed\n"); 

    case EBADF:
      printf("The file descriptor's underlying stream is not a valid file descriptor open for reading\n"); 

    /* 
     * case EILSEQ:
     *   printf("Input byte sequence does not form a valid character\n"); 
     */

    case EINTR:
      printf("A signal interrupted the call\n"); 

    case EINVAL:
      printf("There are insufficient arguments\n"); 

    case EIO:
      printf("A physical I/O error has occurred\n"); 

    case EOVERFLOW:
      printf("The file is a regular file and an attempt was made to read at or beyond the offset associated with the corresponding stream\n"); 

    case ENOMEM:
      printf("Insufficient storage space is available\n"); 

    case ENXIO:
      printf("A request was made of a non-existent device, or the request was outside the capabilities of the device\n");
  }
#endif
}