home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / CLIBSRC3.ZIP / IOERROR.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  7.0 KB  |  195 lines

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