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: record locking


On Mon, Mar 25, 2002 at 05:57:39PM -0500, Phil Edwards wrote:
> On Sun, Mar 24, 2002 at 06:03:53PM +0100, Matthias Weiss wrote:
> > AFAIK I have to do an additional "open" call to the
> > libc API to get a file descriptor that allows me
> > to use flock.
> 
> With recent versions of the library you can use an extension, fstream::fd(),
> to obtain the underlying file descriptor.

What do you mean with recent version??

I've got 3.0.4 and the compiler says:

no matching function for call to `std::basic_fstream<char, 
   std::char_traits<char> >::fd()

when I use fd() like this:

fstream my_file;
...
int fd = my_file.fd();

> > So my request would be to integrate this in the fstream
> > class as an extension or to add a member function that 
> > returns the file descriptor.
> 
> Or you could extend fstream (or one of the buffer classes) to do the
> locking for you at appropriate times.  That way the "non-standard-ness"
> would be explicitly in your code, rather than depending on a particular
> library extension.

I don't think I can do that.

The basic_fstream class uses it's private member _M_filebuf, which is of type
basic_filebuf, to open a file. basic_filebuf has a private member _M_file which
got the file descriptor from its base class, the struct FILE.

Because these are private members, my class that I'd derive from basic_fstream
wouldn't have any access to the file descriptor because of private member protection.


matthias


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