tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [PATCH] rfc: reuse previously closed descriptor in freopen()

On Mon, Aug 25, 2008 at 03:33:22PM +0300, Andy Shevchenko wrote:
 > What is the advantage to not reuse previously closed descriptor for fd >= 3?

I'm not sure I understand your question; but the intent of the code is
that the stdio files "stdin", "stdout", and "stderr" should remain
connected to fds 0, 1, and 2. Your patch breaks this if someone
freopens stderr and the new fd is, say, 8.

Perhaps you meant to test wantfd < 3 rather than f < 3? But even then,
the principle of least surprise suggests that freopen, which is
supposed to adjust an existing open FILE * rather than create a new
one, should retain the same fd if possible.

And finally, if it ain't broke, don't fix it - this is stdio and
potentially affects a lot of code, not all of which is well written or
defensive (or even correct) about its assumptions.

David A. Holland

Home | Main Index | Thread Index | Old Index