This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: How to implement File locking for fstream class object
- From: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>
- To: Ajay Bansal <Ajay_Bansal at infosys dot com>
- Cc: libstdc++ at gcc dot gnu dot org, Pankaj Garg <pankaj_garg at infosys dot com>,Gagan Puri <gaganpuri at infosys dot com>
- Date: Mon, 3 Feb 2003 15:30:39 +0000
- Subject: Re: How to implement File locking for fstream class object
- References: <2B721C6525F0D411B1E900B0D0226BDDFD2329@mohmsg01.ad.infosys.com>
On Mon, Feb 03, 2003 at 08:38:16PM +0530, Ajay Bansal wrote:
> I am using fstream in my application. I need to implement locking on my
> file. Earlier fd method of filebuf class was available which gave me
> filedescriptor. That file descriptor can be used by lockf or fcntl
> system calls to implement file locking. How do I achive file locking
> using me fstream object now?????
std::fstream can no longer be constructed from a file descriptor, since
this was a non-standard extension.
Instead, libstdc++-v3 provides a derived streambuf class that can be
constructed from a file descriptor, this streambuf can then be used by
an fstream. Please see the notes in the Extensions chapter of the docs.
http://gcc.gnu.org/onlinedocs/libstdc++/ext/howto.html#2
> Following is the code snipet used for locking the file:
>
> fcntl(m_file.rdbuf()->fd(), F_SETFD, FD_CLOEXEC);
>
> How can achive the above functionality(file locking) on gcc 3.2.1????
This should be possible, if you use the non-standard stdio_filebuf class
instead of std::basic_filebuf
(I might try to do a simple example of how to use the stdio_filebuf, and
possibly make the notes easier to find from the docs front page.)
jon
--
If one tells the truth, one is sure, sooner or later, to be found out.
- Oscar Wilde