home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / SYS / SIGNAL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  904 b   |  37 lines

  1. /* sys/signal.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <os2emx.h>
  5. #include <signal.h>
  6. #include <errno.h>
  7. #include "syscalls.h"
  8. #include "syssig.h"
  9.  
  10. void (*__signal (int sig, void (*handler)()))(int sig)
  11. {
  12.   void (*prev)();
  13.   int pend;
  14.  
  15.   if (sig < 1 || sig >= NSIG || sig == SIGKILL)
  16.     {
  17.       errno = EINVAL;
  18.       return (SIG_ERR);
  19.     }
  20.   prev = _sys_sig_handlers[sig];
  21.   if (handler == SIG_ACK)
  22.     {
  23.       _sys_sig_ack_req[sig] = 0;
  24.       pend = _sys_sig_pending[sig];
  25.       _sys_sig_pending[sig] = 0;
  26.       if (sig == SIGINT)
  27.         DosAcknowledgeSignalException (XCPT_SIGNAL_INTR);
  28.       else if (sig == SIGBREAK)
  29.         DosAcknowledgeSignalException (XCPT_SIGNAL_BREAK);
  30.       if (pend && __raise (sig) != 0)
  31.         return (SIG_ERR);
  32.     }
  33.   else
  34.     _sys_sig_handlers[sig] = handler;
  35.   return (prev);
  36. }
  37.