home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / IOERROR.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  5.5 KB  |  170 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - ioerror.cas
  3.  *
  4.  * function(s)
  5.  *        __IOerror - set error variables
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18. #pragma inline
  19. #include <asmrules.h>
  20. #include <_io.h>
  21. #include <errno.h>
  22.  
  23. int    _doserrno = 0;
  24.  
  25. char    _dosErrorToSV [] =
  26. {
  27.     0,            /*  0 - OK             */
  28.     EINVAL,        /*  1 - e_badFunction         */
  29.     ENOENT,        /*  2 - e_fileNotFound         */
  30.     ENOENT,        /*  3 - e_pathNotFound         */
  31.     EMFILE,        /*  4 - e_tooManyOpen         */
  32.     EACCES,        /*  5 - e_accessDenied         */
  33.     EBADF,        /*  6 - e_badHandle         */
  34.     ENOMEM,        /*  7 - e_mcbDestroyed         */
  35.     ENOMEM,        /*  8 - e_outOfMemory         */
  36.     ENOMEM,        /*  9 - e_badBlock         */
  37.     E2BIG,        /* 10  e_badEnviron        */
  38.     ENOEXEC,        /* 11  e_badFormat        */
  39.     EACCES,        /* 12  e_badAccess        */
  40.     EINVAL,        /* 13  e_badData        */
  41.     EFAULT,        /* 14  reserved            */
  42.     EXDEV,        /* 15  e_badDrive        */
  43.     EACCES,        /* 16  e_isCurrentDir        */
  44.     ENOTSAM,        /* 17  e_notSameDevice        */
  45.     ENOENT,        /* 18  e_noMoreFiles        */
  46.     EROFS,        /* 19  e_readOnly        */
  47.     ENXIO,        /* 20  e_unknownUnit        */
  48.     EBUSY,        /* 21  e_notReady        */
  49.     EIO,        /* 22  e_unknownCommand     */
  50.     EIO,        /* 23  e_dataError        */
  51.     EIO,        /* 24  e_badRequestLength   */
  52.     EIO,        /* 25  e_seekError        */
  53.     EIO,        /* 26  e_unknownMedia        */
  54.     ENXIO,        /* 27  e_sectorNotFound     */
  55.     EBUSY,        /* 28  e_outOfPaper        */
  56.     EIO,        /* 29  e_writeFault        */
  57.     EIO,        /* 30  e_readFault        */
  58.     EIO,        /* 31  e_generalFault        */
  59.     EACCES,        /* 32  e_sharing        */
  60.     EACCES,        /* 33  e_lock            */
  61.     ENXIO,        /* 34  e_diskChange        */
  62.     ENFILE,        /* 35  e_FCBunavailable     */
  63.     ENFILE,        /* 36  e_sharingOverflow    */
  64.     EFAULT, EFAULT,
  65.     EFAULT, EFAULT,
  66.     EFAULT, EFAULT,
  67.     EFAULT, EFAULT,
  68.     EFAULT, EFAULT,
  69.     EFAULT, EFAULT,
  70.     EFAULT,        /* 37-49  reserved        */
  71.     ENODEV,        /* 50  e_networkUnsupported */
  72.     EBUSY,        /* 51  e_notListening        */
  73.     EEXIST,        /* 52  e_dupNameOnNet        */
  74.     ENOENT,        /* 53  e_nameNotOnNet        */
  75.     EBUSY,        /* 54  e_netBusy        */
  76.     ENODEV,        /* 55  e_netDeviceGone        */
  77.     EAGAIN,        /* 56  e_netCommandLimit    */
  78.     EIO,        /* 57  e_netHardError        */
  79.     EIO,        /* 58  e_wrongNetResponse   */
  80.     EIO,        /* 59  e_netError        */
  81.     EINVAL,        /* 60  e_remoteIncompatible */
  82.     EFBIG,        /* 61  e_printQueueFull     */
  83.     ENOSPC,        /* 62  e_printFileSpace     */
  84.     ENOENT,        /* 63  e_printFileDeleted   */
  85.     ENOENT,        /* 64  e_netNameDeleted     */
  86.     EACCES,        /* 65  e_netAccessDenied    */
  87.     ENODEV,        /* 66  e_netDeviceWrong     */
  88.     ENOENT,        /* 67  e_netNameNotFound    */
  89.     ENFILE,        /* 68  e_netNameLimit        */
  90.     EIO,        /* 69  e_netBIOSlimit        */
  91.     EAGAIN,        /* 70  e_paused            */
  92.     EINVAL,        /* 71  e_netRequestRefused  */
  93.     EAGAIN,        /* 72  e_redirectionPaused  */
  94.     EFAULT, EFAULT,
  95.     EFAULT, EFAULT,
  96.     EFAULT, EFAULT,
  97.     EFAULT,        /* 73- 79  reserved        */
  98.     EEXIST,        /* 80  e_fileExists        */
  99.     EFAULT,        /* 81  reserved            */
  100.     ENOSPC,        /* 82  e_cannotMake        */
  101.     EIO,        /* 83  e_failInt24        */
  102.     ENFILE,        /* 84  e_redirectionLimit   */
  103.     EEXIST,        /* 85  e_dupRedirection     */
  104.     EPERM,        /* 86  e_password        */
  105.     EINVAL,        /* 87  e_parameter        */
  106.     EIO,        /* 88  e_netDevice        */
  107. };
  108.  
  109.  
  110. /*-----------------------------------------------------------------------*
  111.  
  112. Name        __IOerror - set error variables
  113.  
  114. Usage        #include <_io.h>
  115.         int  pascal  __IOerror (int dosErr);
  116.  
  117. Prototype in    _io.h
  118.  
  119. Description    dosErr    is  a  MSDOS  error  number,  or,  if negative, the
  120.         negative of a System V error number.
  121.  
  122.         __IOerror  sets    the  error  number  into  _doserrno. If not
  123.         negative then  translate it into  System V equivalent.    Put
  124.         (translated) value into _errno.
  125.  
  126. Return value    __IOerror returns -1, the usual RTL error return.
  127.  
  128. *------------------------------------------------------------------------*/
  129. int pascal near __IOerror(int dosErr)
  130. {
  131.     int    val = dosErr;
  132.  
  133.     if (val < 0)
  134.         goto ser_maybeSVerr;
  135.  
  136.     if (val <= e_dosFinalError)
  137.         goto ser_dosError;
  138.  
  139. /*
  140.   Being defensive, we must assume that the error routine can be passed
  141.   a bad argument.  In such circumstances, complaining about the
  142.   parameter seems the most reasonable thing to do.
  143. */
  144. ser_errorFault:
  145.     val = e_parameter;
  146.  
  147. ser_dosError:
  148.     _doserrno = val;
  149.  
  150.     val = _dosErrorToSV[val];
  151.     goto ser_end;
  152.  
  153. /*
  154.   This function may be called with a negated System V error code when
  155.   no appropriate MSDOS error code exists.  In such cases the doserrno
  156.   is set to non-zero, but using a number which has no known cause.
  157. */
  158.  
  159. ser_maybeSVerr:
  160.     val = -val;
  161.     if (val > _sys_nerr)
  162.         goto ser_errorFault;
  163.  
  164.     _doserrno = -1;
  165.  
  166. ser_end:
  167.     errno = val;
  168.     return -1;
  169. }
  170.