[Top][All Lists]

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

Re: Why does close_stdout close stdout and stderr?

From: Paul Eggert
Subject: Re: Why does close_stdout close stdout and stderr?
Date: Wed, 8 May 2019 21:42:23 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

Florian Weimer wrote:
You can achieve that "actual close call" using

   error = close(dup(fileno(stdout)));

so you don't actually need to "fclose" if you don't want to.
Any 'close' will do, it doesn't have to be the "last close".
Hah, thanks for this suggestion!  So something good came out of this
thread after all.  The big advantage of this approach is that this will
preserve the descriptor and the stream, so that further diagnostics from
the process are not suppressed.

That trick won't work if the dup fails.

Also, I worry that the trick won't port to non-Linux kernels, so it would have to be '#ifdef __linux__' or something like that.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]