home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / CTRLBRK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  2.3 KB  |  73 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - ctrlbrk.c
  3.  *
  4.  * function(s)
  5.  *        hentry  - hook to call user's control break handler
  6.  *        ctrlbrk - sets control-break handler
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*[]------------------------------------------------------------[]*/
  10. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #include <dos.h>
  20. #include <process.h>
  21.  
  22. static    int    (*Hfunc)(void);
  23.  
  24. /*---------------------------------------------------------------------*
  25.  
  26. Name        hentry - hook to call user's control break handler
  27.  
  28. Usage        static    void interrupt far hentry();
  29.  
  30. Prototype in    local to this module
  31.  
  32. Description    interprets the return value from the ctrl break
  33.         handler
  34.  
  35. Return value    nothing
  36.  
  37. *---------------------------------------------------------------------*/
  38.  
  39. static    void interrupt far hentry()
  40. {
  41.     if    (!(*Hfunc)())
  42.         _exit(0);
  43. }
  44.  
  45.  
  46. /*--------------------------------------------------------------------------*
  47.  
  48. Name        ctrlbrk - sets control-break handler
  49.  
  50. Usage        void ctrlbrk(int (*fptr)(void));
  51.  
  52. Prototype in    dos.h
  53.  
  54. Description    ctrlbrk sets  a new control-break handler  function pointed
  55.         to by fptr.  The interrupt vector 0x23 is  modified to call
  56.         the named function.
  57.  
  58.         The  named   function  is  not    called     directly.  ctrlbrk
  59.         establishes a  DOS interrupt handler  that calls the  named
  60.         function.
  61.  
  62. Return value    ctrlbrk returns nothing. The  handler function returns 0 to
  63.         abort the current  program; any other value will  cause the
  64.         program to resume execution.
  65.  
  66. *---------------------------------------------------------------------------*/
  67. void    ctrlbrk(int (*fptr)())
  68. {
  69.     Hfunc = fptr;
  70.  
  71.     setvect(0x23, hentry);
  72. }
  73.