"Brian S. Julin" wrote:
> 
> On Thu, 24 May 2001, Brian S. Julin wrote:
> 
> Second, and I don't know what to do about this, display-terminfo
> is broken in that if you ggiOpen it on stdin/stdout, then ggiClose
> it (which closes the descriptors), then ggiOpen it again on stdin/stdout,
> fdopen on the stdout/stdin descriptors fails the second time, which
> causes a segfault.
> 
> This is despite the code:
> 
> priv->f_out = fdopen(fileno(stdout), "w");
> 
> ...which would appear to be trying to avoid just this problem, but apparently
> does not quite succeed at it.

Is it intended to (somehow) duplicate stdout ? If so, why not merely use
dup(2) ? The duplication here happens only on high level streams, not on
the underlying file descriptor.

You say that ggiClose() closes the descriptor. I guess you mean it does
fclose(priv->f_out). The problem here is that fclose() causes a close()
of the underlying fd (stdout).

I don't know if I quite understood the issue but I would propose
something like:
priv->f_out = fdopen(dup(STDOUT_FILENO), "w");

Now, a fclose(priv->f_out) just closes the duplicated fd, letting stdout
open for a further ggiOpen().

Hope this helps,

Xavier

Reply via email to