> maybe there's a better way of checking for closure than ftell
http://software.jessies.org/svn/salma-hayek/trunk/native/all/ruby-launcher/ruby-launcher.cpp
suggests:
// This might look obscure but the man page suggests that it's a
POSIX-compliant way
// of testing whether a file descriptor is open.
int rc = fcntl(targetFd, F_GETFL);
if (rc != -1) {
return;
}
if (errno != EBADF) {
Unlike make, that code only needs to worry about POSIX. I quote it mainly,
then, to suggest that doing this portably might prove surprisingly hard. It
would be portable and, if David's plausible explanation is right, more
intention-revealing, but more complicated and less efficient, to keep track of
whether stdout has ever been written to, and only close it then.
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of David Boyce
Sent: Wednesday, April 20, 2011 21:32
To: Philip Guenther
Cc: bug-make
Subject: Re: [bug #33134] spurious error when stdout is already closed
On Thu, Apr 21, 2011 at 12:00 AM, Philip Guenther <[email protected]> wrote:
> Why is that a mistake?
>
> It appears you're saying that make should complain about failures to
> write to stdout for reasons like EIO, ENOSPC, and EOVERFLOW, but
> *not* for EBADF.
I think you're still not getting my point here. I do not believe this
has anything to do with *writes* at all, failed or otherwise. Make is
attempting to close something that's already closed and complaining
when it doesn't work. POSIX is quite clear that fclose on a closed
stream results in an error condition.
> (Actually, your patch doesn't just ignore EBADF errors: it ignores
> EPIPE errors, as the ftell() will fail on the pipe. Why is that a
> good idea?)
You're right on this. An earlier version of my change, when it was
implemented within close_stdout(), looked something like
if (ftell(stdout) == -1 && errno == EBADF) ...
but I lost the EBADF test when I redid it. That was a mistake, and
maybe there's a better way of checking for closure than ftell anyway,
but the basic point of not closing something unless it was open
remains.
David B
_______________________________________________
Bug-make mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-make
_______________________________________________
Bug-make mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-make