RISC-V: testsuite: Remove deprecated compatibility headers
[official-gcc.git] / libgm2 / libm2log / Break.c
blob0b878d8c27e14f50d562e55c98b767b31be78750
1 /* Break.c implements an interrupt handler for SIGINT.
3 Copyright (C) 2004-2022 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 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, or (at your option)
11 any later version.
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
27 #include <config.h>
29 #if defined(HAVE_STDIO_H)
30 #include <stdio.h>
31 #endif
33 #if defined(HAVE_STDARG_H)
34 #include <stdarg.h>
35 #endif
37 #if defined(HAVE_STDLIB_H)
38 #include <stdlib.h>
39 #endif
41 #if defined(HAVE_MALLOC_H)
42 #include <malloc.h>
43 #endif
45 typedef void (*PROC) (void);
47 #if defined(HAVE_SIGNAL_H)
48 #include <signal.h>
50 struct plist
52 PROC proc;
53 struct plist *next;
56 static struct plist *head = NULL;
58 /* localHandler - dismisses the parameter, p, and invokes the GNU
59 Modula-2 handler. */
61 static void
62 localHandler (int p)
64 if (head != NULL)
65 head->proc ();
68 /* EnableBreak - enable the current break handler. */
70 void
71 Break_EnableBreak (void)
73 signal (SIGINT, localHandler);
76 /* DisableBreak - disable the current break handler (and all
77 installed handlers). */
79 void
80 Break_DisableBreak (void)
82 signal (SIGINT, SIG_IGN);
85 /* InstallBreak - installs a procedure, p, to be invoked when a
86 ctrl-c is caught. Any number of these procedures may be stacked.
87 Only the top procedure is run when ctrl-c is caught. */
89 void
90 Break_InstallBreak (PROC p)
92 struct plist *q = (struct plist *)malloc (sizeof (struct plist));
94 if (q == NULL)
96 perror ("out of memory error in module Break");
97 exit (1);
99 q->next = head;
100 head = q;
101 head->proc = p;
104 /* UnInstallBreak - pops the break handler stack. */
106 void
107 Break_UnInstallBreak (void)
109 struct plist *q = head;
111 if (head != NULL)
113 head = head->next;
114 free (q);
117 #else
118 void
119 Break_EnableBreak (void)
122 void
123 Break_DisableBreak (void)
126 void
127 Break_InstallBreak (PROC *p)
130 void
131 Break_UnInstallBreak (void)
134 #endif