home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tc20 / ssignal.c < prev    next >
Text File  |  1988-08-28  |  4KB  |  127 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - ssignal.c
  3.  *
  4.  * function(s)
  5.  *        ssignal - implements software signals
  6.  *        gsignal - implements software signals
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*[]---------------------------------------------------[]*/
  10. /*|                            |*/
  11. /*|    Turbo C Run Time Library - Version 1.5        |*/
  12. /*|                            |*/
  13. /*|                            |*/
  14. /*|    Copyright (c) 1987,88 by Borland International    |*/
  15. /*|    All Rights Reserved.                |*/
  16. /*|                            |*/
  17. /*[]---------------------------------------------------[]*/
  18.  
  19.  
  20. #include <signal.h>
  21.  
  22. #pragma    warn -sus
  23.  
  24. static int (*Sigtbl[16])() =
  25.     {
  26.         0,
  27.         SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL,
  28.         SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL,
  29.         SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL,
  30.     };
  31.  
  32. #pragma    warn .sus
  33.  
  34. /*---------------------------------------------------------------------*
  35.  
  36. Name            ssignal - implements software signals
  37.  
  38. Usage           int (*ssignal(int sig, int (*action)( ))( );
  39.  
  40. Related
  41. functions usage int gsignal(int sig);
  42.  
  43. Prototype in    signal.h
  44.  
  45. Description     ssignal and gsignal implement a software-signalling
  46.                 facility. Software signals are associated with integers in the
  47.                 range from 1 to 15.
  48.  
  49.                 gsignal raises the signal given by sig and executes the action
  50.                 routine.
  51.  
  52.                 ssignal is used to establish an action routine for servicing a
  53.                 signal. The first argument to ssignal, sig, is a number
  54.                 identifying the type of signal for which an action is
  55.                 established.
  56.  
  57.                 The second argument, action, defines the action; it is either
  58.                 the name of a user-defined action function or one of the
  59.                 constants SIG_DFL (default) or SIG_IGN (ignore). These constants
  60.                 are defined in signal.h.
  61.  
  62.                 If an action function has been established for sig, then that
  63.                 action is reset to SIG_DFL, and the action function is entered
  64.                 with argument sig.
  65.  
  66. Return value    ssignal returns the action previously established
  67.                 or, if the signal number is illegal, returns SIG_DFL.
  68.  
  69.                 gsignal returns the value returned to it by the action
  70.                 function. gsignal's return values for actions assigned to sig
  71.                 are listed in the following:
  72.  
  73.                         Action          Return
  74.  
  75.                         SIG_IGN         1
  76.                         SIG_DFL         0
  77.                     Illegal value or    0
  78.                     no action specified
  79.  
  80.                 In all cases, gsignal takes no action other than returning a
  81.                 value.
  82.  
  83. *---------------------------------------------------------------------*/
  84. int (*ssignal(register int sig, int (*action)()))()
  85. {
  86.     int    (*oldact)();
  87.  
  88. #pragma    warn -sus
  89.     if (sig < 1 || sig > 15)
  90.         return (SIG_DFL);
  91. #pragma    warn .sus
  92.  
  93.     oldact = Sigtbl[sig];
  94.     Sigtbl[sig] = action;
  95.  
  96.     return (oldact);
  97. }
  98.  
  99.  
  100. /*---------------------------------------------------------------------*
  101.  
  102. Name            gsignal - implements software signals
  103.  
  104. Usage           int gsignal(int sig);
  105.  
  106. Prototype in    signal.h
  107.  
  108. Description     see ssignal above
  109.  
  110. *---------------------------------------------------------------------*/
  111. int gsignal(register int sig)
  112. {
  113.     int    (*action)(int);
  114.  
  115.     if (sig < 1 || sig > 15)
  116.         return (0);
  117. #pragma    warn -sus
  118.     action = Sigtbl[sig];
  119.     if (action == SIG_IGN)
  120.         return (1);
  121.     if (action == SIG_DFL)
  122.         return (0);
  123.     Sigtbl[sig] = SIG_DFL;
  124. #pragma    warn .sus
  125.     return ((*action)(sig));
  126. }
  127.