This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Legalize access to file descriptors now! (So sue me.)


Earlier, I wrote:

> > On Wed, Feb 16, 2005 at 11:56:29PM +0100, Richard B. Kreckel wrote:
> > 
> > > Since we've had the discussion whether to allow access to file descriptors
> > > from C++ stream objects more than once without any result, I've had to
> > > hack my way through to the file descriptors by applying a good amount of
> > > brute force (not to mention all the beer).
> > > 
> > > So, here is my lament: http://www.ginac.de/~kreckel/fileno/.  Could you
> > > folks please, please make the access a little bit more smooth?  We need
> > > the
> > > file descriptor.  We are going to get it.  Don't prolong the agony.
> 
> Would something like the following avoid the undefined behaviour of
> downcasting basic_filebuf* to my_filebuf* in the GCC 3.4 case ?
[snip ugly hack]
> If that code's legal then that means that there are legal ways of getting
> the fd for all valid types in libstdc++ 3.4.2 and up.

(I must stop replying to myself ...)

Forgot to add that if that hack's not legal then Richard still wants a
nice way of getting the fd from a std::basic_filebuf.

Also, Richard's fileno() doesn't help for user-defined streams that are
based on a file descriptor (e.g. a socket class).

If this were something that should be available as part of some
POSIX-C++-binding then it should be as extensible as IOStreams and
should let user-defined streams to be used with fileno() too.


Could add a virtual function to std::basic_ios, which returns -1 by
default but can be overridden, but that would be GCC-specific, and would
be a step backwards as far as strict std-conformance goes.

Could provide a template that can be specialised for certain types to
obtain the file descriptor (possibly using some nefarious
implementation-defined means for types provided by the stdlib) but that
would need the dynamic type of the stream to be available (I think).


I see that Marc Rochkind's Ux [1] provides a fd abstraction, but doesn't
provide any way of intermixing it with IOStreams (though that is
probably just because there is no standard way of doing it.)

jon

[1] http://www.basepath.com/aup/ex/group__Ux.html

-- 
"Surrealism aims at the total transformation
 of the mind and all that resembles it"
	- Breton


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]