List of routines safe to use in signals?

Jonathan I. Kamens jik at athena.mit.edu
Wed Dec 12 16:05:27 AEST 1990


In article <59190 at brunix.UUCP>, cgy at cs.brown.edu (Curtis Yarvin) writes:
|> Hey, excuse me if I'm being a complete newbie.  But how can a reentrant
|> library routine, say "strcpy", cause problems in this case?

  The obvious answer is, "How do you *know* the routine is reentrant?"

  Now, in response to that, you can say, "Why would anyone have any reason to
write a strcpy function that isn't reentrant?" but that question misses the
point.  You can't assume anything about library functions that isn't in the
spec for the function.  If the man page (or, more recently, the ANSI spec, or
the POSIX spec, or whatever) for the function says that it's reentrant,
then it is, and you can count on it being reentrant.  However, if that is not
specified, then you cannot make any assumptions about whether or not the
function is reentrant.

  Obviously, a signal handler that calls strcpy isn't going to have any
trouble on the vast majority of systems currently in existence, if not on all
systems.  But there's no way to know that for sure.  Furthermore, there's the
"slippery slope" problem which says that if you first assume that strcpy is
reentrant, you may continue to make that assumption with more and more
functions, until suddenly you'll find yourself calling printf :-).

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.unix.programmer mailing list