Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What was filebuf::openprot intended for, and does it have a replacement?

Tags:

c++

I'm in the middle of fixing some rather old C++ code that used the old-style iostream library, and I came across the following non-compiling lines of code:

::ofstream ofile;
ofile.open("filename", ios::trunc, filebuf::openprot);

I get this error:

error C2039: 'openprot' : is not a member of 'std::basic_filebuf<_Elem,_Traits>'

So obviously it's something that's not around any more. The problem is, I can't find any information on what openprot did as a parameter, and I therefore can't replace it with something new, and I'm afraid to remove the parameter altogether.

Anyone with any historical C++ knowledge know what this thing did?

like image 712
Archimaredes Avatar asked Dec 19 '12 23:12

Archimaredes


People also ask

What is the function of Filebuf?

In a program that receives input from an fstream object (a file), you can associate the fstream object with a filebuf object, and then use the filebuf object to move the get or put pointer forward or backward in the file. You can also use filebuf member functions to determine the length of the file.

What is the Filebuf function in C++?

Description. filebuf s specialize streambuf s to use a file as a source or sink of characters. Characters are consumed by doing writes to the file, and are produced by doing reads. When the file is seekable, a filebuf allows seeks. At least 4 characters of putback are guaranteed.


2 Answers

That parameter indicates/indicated the protection mode to open the file with. It shows up in this IBM Legacy Class Library Reference.

filebuf::openprot is/was the default argument to the fstream class family constructors and open functions' prot parameter, which indicates what protection mode the file should be opened/created with.

The default protection mode used when opening files.

For example, on your system it might be 0644, meaning that if the file is created, the owner will have read/write permissions, and everyone else will have read-only.

Seeing as in your case the default argument was being passed in anyway, I would say that it's safe to just remove.

like image 154
Anthony Avatar answered Oct 14 '22 22:10

Anthony


According to the Visual Studio 6.0 documentation, openprot uses the operating system's default:

The file protection specification; defaults to the static integer filebuf::openprot, which is equivalent to the operating system default (filebuf::sh_compat for MS-DOS).

like image 22
Foggzie Avatar answered Oct 14 '22 20:10

Foggzie