Mercurial > hg > Members > kono > nitros9-code
changeset 600:0fa5d3280b5e
All refentries finished.
author | roug |
---|---|
date | Fri, 15 Nov 2002 21:49:51 +0000 |
parents | 7a260a55c5ee |
children | 8b8736b66631 |
files | docs/ccguide/intercept.refentry |
diffstat | 1 files changed, 55 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/docs/ccguide/intercept.refentry Fri Nov 15 21:49:51 2002 +0000 +++ b/docs/ccguide/intercept.refentry Fri Nov 15 21:49:51 2002 +0000 @@ -23,7 +23,61 @@ <refsect1><title>Description</title> <para> -Placeholder +Intercept instructs OS-9 to pass control to the function "func" +when an interrupt (signal) is received by the current process. +</para> +<para> +If the interrupt processing function has an argument, it will +contain the value of the signal received. On return from +"func", the process resumes at the point in the program where +it was interrupted by the signal. "Interrupt()" is an +alternative to the use of "signal()" to process interrupts. +</para> +<para> +As an example, suppose we wish to ensure that a partially +completed output file is deleted if an interrupt is received. +The body of the program might include: +<programlisting> +char *temp_file = "temp"; /* name of temporary file */ +int pn=0; /* path number */ +int intrupt(); /* predeclaration */ + +... + +intercept(intrupt); /* route interrupt processing */ +pn = creat(temp_file,3); /* make a new file */ + +... + +write(pn,string,count); /* write string to temp file */ + +... + +close(pn); +pn=0; + +... +</programlisting> +The interrupt routine might be coded: +<programlisting> +intrupt(sig); +{ + if (pn){ /* only done if pn refers to an open file */ + close(pn); + unlink(temp_file); /* delete */ + } +exit(sig); +} +</programlisting> +</para> +</refsect1> + +<refsect1><title>Caveats</title> +<para> +"Intercept()" and "signal()" are mutually incompatible so that +calls to both must not appear in the same program. The linker +guards against this by giving an "entry name clash - _sigint" +error if it is attempted. </para> </refsect1>