466
|
1 <refentry id="intercept">
|
|
2 <refnamediv>
|
468
|
3 <refname>Intercept</refname>
|
|
4 <refpurpose>set function for interrupt processing</refpurpose>
|
466
|
5 </refnamediv>
|
|
6
|
|
7 <refsynopsisdiv>
|
|
8 <funcsynopsis>
|
|
9 <funcprototype>
|
|
10 <funcdef><function>intercept</function></funcdef>
|
570
|
11 <paramdef>int <parameter>(* func)</parameter>
|
|
12 <funcparams>int</funcparams></paramdef>
|
466
|
13 </funcprototype>
|
|
14 </funcsynopsis>
|
|
15
|
|
16 </refsynopsisdiv>
|
|
17
|
542
|
18 <refsect1><title>Assembler Equivalent</title>
|
|
19 <para>
|
|
20 os9 F$ICPT
|
|
21 </para>
|
|
22 </refsect1>
|
|
23
|
466
|
24 <refsect1><title>Description</title>
|
|
25 <para>
|
600
|
26 Intercept instructs OS-9 to pass control to the function "func"
|
|
27 when an interrupt (signal) is received by the current process.
|
|
28 </para>
|
|
29 <para>
|
|
30 If the interrupt processing function has an argument, it will
|
|
31 contain the value of the signal received. On return from
|
|
32 "func", the process resumes at the point in the program where
|
|
33 it was interrupted by the signal. "Interrupt()" is an
|
|
34 alternative to the use of "signal()" to process interrupts.
|
|
35 </para>
|
|
36 <para>
|
|
37 As an example, suppose we wish to ensure that a partially
|
|
38 completed output file is deleted if an interrupt is received.
|
|
39 The body of the program might include:
|
|
40 <programlisting>
|
|
41 char *temp_file = "temp"; /* name of temporary file */
|
|
42 int pn=0; /* path number */
|
|
43 int intrupt(); /* predeclaration */
|
|
44
|
|
45 ...
|
|
46
|
|
47 intercept(intrupt); /* route interrupt processing */
|
|
48 pn = creat(temp_file,3); /* make a new file */
|
|
49
|
|
50 ...
|
|
51
|
|
52 write(pn,string,count); /* write string to temp file */
|
|
53
|
|
54 ...
|
|
55
|
|
56 close(pn);
|
|
57 pn=0;
|
|
58
|
|
59 ...
|
|
60 </programlisting>
|
|
61 The interrupt routine might be coded:
|
|
62 <programlisting>
|
|
63 intrupt(sig);
|
|
64 {
|
|
65 if (pn){ /* only done if pn refers to an open file */
|
|
66 close(pn);
|
|
67 unlink(temp_file); /* delete */
|
|
68 }
|
|
69 exit(sig);
|
|
70 }
|
|
71 </programlisting>
|
|
72 </para>
|
|
73 </refsect1>
|
|
74
|
|
75 <refsect1><title>Caveats</title>
|
|
76 <para>
|
|
77 "Intercept()" and "signal()" are mutually incompatible so that
|
|
78 calls to both must not appear in the same program. The linker
|
|
79 guards against this by giving an "entry name clash - _sigint"
|
|
80 error if it is attempted.
|
466
|
81 </para>
|
|
82 </refsect1>
|
542
|
83
|
|
84 <refsect1><title>See Also</title>
|
|
85 <para>
|
|
86 <link linkend="signal">signal()</link>
|
|
87 </para>
|
|
88 </refsect1>
|
|
89
|
466
|
90 </refentry>
|