Requesting help on intricacies of duplicated file descriptors.

Rich Felker dalias at aerifal.cx
Mon Jul 24 22:08:13 UTC 2006


On Mon, Jul 24, 2006 at 09:41:29AM -0400, Rob Landley wrote:
> On Saturday 22 July 2006 9:07 pm, Garrett Kajmowicz wrote:
> > If I take the following:
> > 
> > fp = fdopen(fileno(stdin)));
> > 
> > Can I have stdin in blocking mode and fp in non-blocking mode? 
> 
> I believe if you dup(fp) you can set the new fd into a different mode than 
> stdin, and the two of them still suck from the same char dev.

Blocking/nonblocking is controlled by the F_SETFL fcntl. This applies
to open file descriptions, not file descriptors. F_SETFD options apply
locally to file descriptors, but the only such option is FD_CLOEXEC.

> Try it and see what happens. :)

:)

As much fun as this is, I would recommend "read the spec and see what
it's supposed to do" instead. In this case there are no broken
implementations that I know of, but that's not always the case with
everything you might apply "try it and see" to. :)

Rich




More information about the uClibc mailing list