Subject: Re: syslog_r (Re: CVS commit: src/lib/libc)
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: SODA Noriyuki <>
List: tech-userlevel
Date: 10/28/2006 06:40:47
>>>>> On Fri, 27 Oct 2006 14:59:09 -0400 (EDT),
      der Mouse <mouse@Rodents.Montreal.QC.CA> said:

>>> I believe we should avoid the word "reentrant",

> Well, unless we really mean it.

Well, I have one question.
Do you think POSIX "_r" functions (e.g. readdir_r()) are reentrant?

You said the word "reentrant" is stronger than async-signal-safe.
That implys POSIX "_r" functions are not reentrant in your sense.

But POSIX uses the word "reentrant" for the "_r" functions.
i.e. What you mean in "reentrant" and what POSIX means in "reentrant"
seems to be different.

That's the reason I think it's better to avoid the word in the manual.

>>> [...] because the word "reentrant" may mean async-signal-safe in
>>> some technical context.

> Not quite; it's stronger than (my understanding of) async-signal-safe.

> An async-signal-safe function may be called from a signal handler
> without taking any particular precautions to make sure that the signal
> can be delivered only at particular times - right?
> A reentrant routine may be called at any point during its own
> execution, for example from a signal handler (or hardware interrupt, in
> environments where that makes sense), to unlimited depth.

Yeah, that was what I intended. Thanks for the clarification.

Actually I prefer this definition more than the POSIX definition
(i.e. POSIX definition sounds wrong for me).
But again, I believe we should not use this definition in our manual,
just because that's different from POSIX's.

>>> For example, Wikipedia ( says:
>>> To be reentrant, a function must hold no static data, must not
>>> return a pointer to static data, must work only on the data
>>> provided to it by the caller, and must not call non-reentrant
>>> functions.

> I think the Wikipedia is wrong.  There is nothing wrong with returning
> pointers to static data in some cases.  For example,

> const char *k_str(int code)
> {
> 	switch (code) {
> 		case K_FOO: return("foo"); break;
> 		case K_BAR: return("bar"); break;
> 		case K_BAZ: return("baz"); break;
> 		default: return("?""?"); break;
> 	}
> }

> is a totally reentrant function, even though it *always* returns a
> pointer to static data.

Yeah, that's right.
Probably the author of the Wikipedia page intended to say "static data
which may be modified".