This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: record locking
- From: Matthias Weiss <matthias dot weiss at inode dot at>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 26 Mar 2002 19:05:23 +0100
- Subject: Re: record locking
- References: <20020324180353.A797@matthias.weiss@inode.at> <20020325175739.A30111@disaster.basement.lan>
- Reply-to: matthias dot weiss at inode dot at
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