home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / file / exterr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-28  |  1.8 KB  |  69 lines

  1. /* EXTERR.C illustrates function:
  2.  *      dosexterr
  3.  */
  4.  
  5. #include <dos.h>
  6. #include <fcntl.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. void errorinfo( void );     /* Prototype */
  11.  
  12. main( int argc, char *argv[] )
  13. {
  14.     int hsource;
  15.  
  16.     /* Open to get file handle and test for errors. Try specifying
  17.      * invalid files to show different errors.
  18.      */
  19.     if( _dos_open( argv[1], O_RDWR, &hsource ) )
  20.         errorinfo();
  21.     printf( "No error\n" );
  22.     _dos_close( hsource );
  23.     exit( 0 );
  24. }
  25.  
  26. void errorinfo()
  27. {
  28.     struct DOSERROR err;
  29.     static char *eclass[] =
  30.     {
  31.         "", "Out of Resource", "Temporary Situation", "Authorization",
  32.         "Internal", "Hardware Failure", "System Failure", "Application Error",
  33.         "Not Found", "Bad Format", "Locked", "Media", "Already Exists",
  34.         "Unknown"
  35.     };
  36.     static char *eaction[] =
  37.     {
  38.         "", "Retry", "Delay Retry", "User", "Abort", "Immediate Exit",
  39.         "Ignore", "Retry After User Intervention"
  40.     };
  41.     static char *elocus[] =
  42.     {
  43.         "", "Unknown", "Block Device", "Net", "Serial Device", "Memory"
  44.     };
  45.  
  46.  
  47.     /* Get error information and display class, action, and locus. */
  48.     dosexterr( &err );
  49.     printf( "Class:\t%s\nAction:\t%s\nLocus:\t%s\nAction\t",
  50.             eclass[err.class], eaction[err.action], elocus[err.locus] );
  51.  
  52.     /* Errors that could be caused by sample _dos_open. You can expand
  53.      * this list to handle others.
  54.      */
  55.     switch( err.exterror )
  56.     {
  57.         case 2:
  58.             printf( "File not found\n" );
  59.             break;
  60.         case 3:
  61.             printf( "Path not found\n" );
  62.             break;
  63.         case 5:
  64.             printf( "Access denied\n" );
  65.             break;
  66.     }
  67.     exit( err.exterror );
  68. }
  69.