home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / CLIBSRC3.ZIP / HARD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  4.9 KB  |  137 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - hard.c
  3.  *
  4.  * function(s)
  5.  *        harderr    - establishes a hardware error handler
  6.  *        hardresume - hardware error handler function
  7.  *        hardretn   - hardware error handler function
  8.  *-----------------------------------------------------------------------*/
  9.  
  10. /*
  11.  *      C/C++ Run Time Library - Version 5.0
  12.  *
  13.  *      Copyright (c) 1987, 1992 by Borland International
  14.  *      All Rights Reserved.
  15.  *
  16.  */
  17.  
  18.  
  19. #include <dos.h>
  20.  
  21. extern void    __harderr(int (*fptr)());        /* in harderr.cas */
  22.  
  23. /*-----------------------------------------------------------------------*
  24.  
  25. Name            harderr - establishes a hardware error handler
  26.  
  27. Usage           void harderr(int (*fptr)());
  28.  
  29. Related
  30. functions usage void hardresume(int rescode);
  31.                 void hardretn(int errcode);
  32.  
  33. Prototype in    dos.h
  34.  
  35. Description     harderr establishes a hardware error handler for the
  36.                 current program. This handler is invoked whenever an interrupt
  37.                 0x24 occurs. (See the MS-DOS Programmer's Reference Manual for a
  38.                 discussion of the interrupt.)  The harderr macro in dos.h maps
  39.                 to the harderr function.
  40.  
  41.                 The function pointed to by fptr will be called when such an
  42.                 interrupt occurs. The handler function will be called with the
  43.                 following arguments:
  44.  
  45.                    handler(int errval, int ax, int bp, int si);
  46.  
  47.                 errval is the error code set in the DI register by MS-DOS.
  48.                 ax, bp, and si are the values MS-DOS sets for the AX,
  49.                 BP, and SI registers, respectively.
  50.  
  51.                 ax indicates whether a disk error or other device error was
  52.                 encountered. If ax is non-negative, a disk error was
  53.                 encountered; otherwise, the error was a device error. For a
  54.                 disk error, ax ANDed with 0x00FF will give the failing drive
  55.                 number (1 = A, 2 = B, etc.).
  56.  
  57.                 bp and si together point to the device driver header of
  58.                 the failing driver.
  59.  
  60.                 The named function is not called directly. harderr establishes
  61.                 a DOS interrupt handler that calls the function.
  62.  
  63.                 peek and peekb can be used to retrieve device information from
  64.                 this driver header. bp is the segment address, and si is
  65.                 the offset.
  66.  
  67.                 The handler may issue bdos calls 1 through 0xC, but any other
  68.                 bdos call will corrupt MS-DOS. In particular, any of the C
  69.                 standard I/O or UNIX-emulation I/O calls may not be used.
  70.  
  71.                 The driver header may not be altered via poke or pokeb.
  72.  
  73.                 The error handler may return or call hardresume to return to
  74.                 MS-DOS. The return value of the handler or rescode (result code)
  75.                 of hardresume contains an abort (2), retry (1), or ignore (0)
  76.                 indicator. The abort is accomplished by invoking DOS interrupt
  77.                 0x23, the control-break interrupt.
  78.  
  79.                 The error handler may return directly to the application
  80.                 program by calling hardretn.
  81.  
  82.                 The Microsoft-compatible _harderr function is similar
  83.                 to harderr, except that the handler is always a far
  84.                 function, the handler is called with slightly different
  85.                 parameters, and the handler is not expected to return
  86.                 a value:
  87.  
  88.                         void far handler (unsigned deverror, unsigned errcode,
  89.                                         unsigned far *devhdr);
  90.  
  91.  
  92. Return value    The handler must return 0 for ignore, 1 for retry,
  93.                 2 for abort, and 3 for fail (DOS 3.0 or later).  harderr
  94.                 itself does not return a value.
  95.  
  96. Portability     Unique to MS-DOS.
  97.  
  98. See also        peek, poke, setjmp
  99.  
  100. *------------------------------------------------------------------------*/
  101. void _CType harderr(int (*fptr)())
  102. {
  103.     __harderr(fptr);
  104. }
  105.  
  106. /*-----------------------------------------------------------------------*
  107.  
  108. Name            hardresume - hardware error handler function
  109.  
  110. Usage           void hardresume(int rescode);
  111.  
  112. Prototype in    dos.h
  113.  
  114. Description     see harderr
  115.  
  116. *------------------------------------------------------------------------*/
  117. void _CType hardresume(int axret)
  118. {
  119.     _hardresume(axret);
  120. }
  121.  
  122. /*-----------------------------------------------------------------------*
  123.  
  124. Name            hardretn - hardware error handler function
  125.  
  126. Usage           void hardretn(int errcode);
  127.  
  128. Prototype in    dos.h
  129.  
  130. Description     see harderr
  131.  
  132. *------------------------------------------------------------------------*/
  133. void _CType hardretn(int retn)
  134. {
  135.     _hardretn(retn);
  136. }
  137.