The errno variable can get trashed

LeFebvre.wbst at XEROX.ARPA LeFebvre.wbst at XEROX.ARPA
Tue Aug 7 00:31:00 AEST 1984


> The solution would seem to be to have the C signal handling mechanism
> save errno before calling the signal routine and restore it after
> the routine has returned.

Alternatively (actually, in lieu of), the signal handling routine itself
could save and restore the value of errno.  It is possible to assign errno
a value explicitly.  The routine "i" in your example could be written:

void i()
{ int olderrno;	/* note the name is exactly 8 characters :-) */
  olderrno = errno;
  signal(SIGALRM,i);
  open(".",1); /* Fails, since is a directory */
  errno = olderrno;
}

Of course, you also have to move the definition of errno to before the
"void i" statement.

	William LeFebvre
	Department of Computer Science
	Rice University
	At Xerox for the summer (but not much longer)



More information about the Comp.unix.wizards mailing list