This is the mail archive of the 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: How to implement File locking for fstream class object

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.

> 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.)


If one tells the truth, one is sure, sooner or later, to be found out.
	- Oscar Wilde

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