Not checking printf's result causes another news bug
Barry Shein
root at bu-cs.UUCP
Sat Aug 17 04:33:26 AEST 1985
All this talk about printf() return values not being checked causing
various catastrophes reminds me of another system that had what might
provide a good back-door solution to this without very much re-coding,
namely the IBM/OS SYNAD=addr option. You could set up a (in unix lingo)
a signal handler and if any I/O error occurred it would interrupt to
that routine. Now this was on a per-write (actually, per I/O) basis but
what I have in mind here is to do something like:
#define printf eprintf
#define fprintf efprintf
then add to main() something like
signal(SIGIOT,myhandler) ; /* choose a signal, SIGIOT seems good*/
and something reasonable for myhandler() and finally:
eprintf(fmt,a,b,c,d,e,f,g...) /* etc or maybe use varargs */
{
int n ;
if((n = printf(fmt,a,b,...)) < 0)
kill(0,SIGIOT) ;
return(n) ;
}
and almost exactly the same for efprintf(fp,...).
(of course, the file with these routines must *not* have the #defines.
Then of course, you get to decide what to do now that you have the
error, but saves you from a lot of re-working of code.
-Barry Shein, Boston University
Just a suggestion.
More information about the Comp.lang.c
mailing list