Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filebuf equivalent ?

Status
Not open for further replies.

Pinpoint

Programmer
Dec 23, 2001
49
GB
Hi,

I need the Unix C++ equivalent of the Windows ifstream/ofstream filebuf setting, ie

os.open("file.dat", ios::eek:ut, filebuf::sh_none) ;

Can anyone tell me if there is one, or some other way to ensure a file cannot be updated twice simultaneously ?

Thanks.
 
I'm not sure what you're after, but it sounds like file locking. If you are on a POSIX compliant system, you could accomplish this with a [tt]fcntl[/tt] call.

//Daniel
 
As far as I know, filebuf::sh_none is not Windows feature, it was part of OLD (more than deptecated) stream library only. The C++ Standard totally ignores file sharing. I think, it's the most serious defect of C++ Std file i/o.
I think, it's impossible to write portable sharing stream file program in C++. Use old good C file i/o library (open or fopen etc). io.h's are non-standard headers, but are nearly identical on Win and Unix (in file sharing aspect).
I will be glad to read more optimistic words about true standard C++ stream file sharing. I was distressed when read C++ Standard file i/o part.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top