sigaction.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* sigaction.c
  2. *
  3. * Copyright (C) 1995 DJ Delorie
  4. *
  5. * (See the README file in this directory for the copyright and license
  6. * history of this file.)
  7. *
  8. * This file is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This file is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this file. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <signal.h>
  22. #include <errno.h>
  23. int
  24. sigaction(int _sig, const struct sigaction *_act, struct sigaction *_oact)
  25. {
  26. int retval = 0;
  27. if (_oact)
  28. {
  29. void (*installed_sig)(int) = signal (_sig, SIG_IGN);
  30. /* FIXME */
  31. if (installed_sig == SIG_ERR)
  32. {
  33. retval = -1;
  34. errno = EINVAL;
  35. }
  36. else
  37. signal (_sig, installed_sig);
  38. _oact->sa_handler = installed_sig;
  39. retval = sigemptyset (&_oact->sa_mask);
  40. _oact->sa_flags = 0;
  41. }
  42. if (_act)
  43. {
  44. if (signal (_sig, _act->sa_handler) == SIG_ERR)
  45. {
  46. retval = -1;
  47. errno = EINVAL;
  48. }
  49. }
  50. return 0;
  51. }