home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / CTRLBRK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.1 KB  |  78 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.  *      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. #include <dos.h>
  19. #include <process.h>
  20.  
  21. #ifdef __TINY__
  22. #define FARINT(f) ((void interrupt far (*)())MK_FP(_CS,f))
  23. #else
  24. #define FARINT(f) f
  25. #endif
  26.  
  27. static  int     (*Hfunc)(void);
  28.  
  29. /*---------------------------------------------------------------------*
  30.  
  31. Name            hentry - hook to call user's control break handler
  32.  
  33. Usage           static  void interrupt far hentry();
  34.  
  35. Prototype in    local to this module
  36.  
  37. Description     interprets the return value from the ctrl break
  38.                 handler
  39.  
  40. Return value    nothing
  41.  
  42. *---------------------------------------------------------------------*/
  43.  
  44. static  void interrupt far hentry()
  45. {
  46.         if      (!(*Hfunc)())
  47.                 _exit(0);
  48. }
  49.  
  50.  
  51. /*--------------------------------------------------------------------------*
  52.  
  53. Name            ctrlbrk - sets control-break handler
  54.  
  55. Usage           void ctrlbrk(int (*fptr)(void));
  56.  
  57. Prototype in    dos.h
  58.  
  59. Description     ctrlbrk sets  a new control-break handler  function pointed
  60.                 to by fptr.  The interrupt vector 0x23 is  modified to call
  61.                 the named function.
  62.  
  63.                 The  named   function  is  not  called   directly.  ctrlbrk
  64.                 establishes a  DOS interrupt handler  that calls the  named
  65.                 function.
  66.  
  67. Return value    ctrlbrk returns nothing. The  handler function returns 0 to
  68.                 abort the current  program; any other value will  cause the
  69.                 program to resume execution.
  70.  
  71. *---------------------------------------------------------------------------*/
  72. void    ctrlbrk(int (*fptr)())
  73. {
  74.         Hfunc = fptr;
  75.  
  76.         setvect(0x23, FARINT(hentry));
  77. }
  78.