File locking in C++

B

barcaroller

I am familiar with file locking in C (flock, fcntl) but I was unable to
find anything similar in C++ (using either fstream or
boost::filesystem). Does anyone know if the C++ libraries support file
locking?

Thanks much.
 
G

Goran

I am familiar with file locking in C (flock, fcntl)

I have no idea what flock and fnctl are. And I just looked upon C99
draft, there's no mention of neither. My conclusion is: there is
__no__ file locking in C (that is, in C standard library).

More seriously, you are looking for things that seem to be outside of
the scope of the language. fnctl, in particular, is part of POSIX
spec. But you can, of course, call that from your C++ code.

Goran.
 
J

James Kanze

I am familiar with file locking in C (flock, fcntl) but I was unable to
find anything similar in C++ (using either fstream or
boost::filesystem). Does anyone know if the C++ libraries support file
locking?

Neither C nor C++ support file locking. In general, support for
anything more than a simple sequential stream is very limited.
More complex operations have to descend to the system level
(different in Windows and Posix), and use it. (Your functions
flock and fcntl are Posix, not C, and are probably not available
under Windows.)
 
R

Richard

[Please do not mail me a copy of your followup]

barcaroller <[email protected]> spake the secret code
I've googled "C++ file locking" and similar phrases. Try it, and
you'll see what I mean. Your link is exactly what I was looking for.
Thank you.

I googled "boost file lock". In general, I've found that "C++" isn't
a good term for google.

Its a bit like searching for my favorite band: "The Who". Many search
engines discard both terms because they "appear too frequently".
Google isn't as bad this way, but there was a point when you couldn't
find anything at all on this megaband simply because search engines
were stupid.
 
O

osmium

Sherm Pendley said:
[email protected] (Richard) said:
[Please do not mail me a copy of your followup]

barcaroller <[email protected]> spake the secret code
I've googled "C++ file locking" and similar phrases. Try it, and
you'll see what I mean. Your link is exactly what I was looking for.
Thank you.

I googled "boost file lock". In general, I've found that "C++" isn't
a good term for google.

Its a bit like searching for my favorite band: "The Who".

Google gives better results if one uses quotation marks, i.e. search
for '"C++" file lock' rather than 'C++ file lock'.

I get 2.1e6 hits for
C++ file lock
and i get 2.1e6 hits for
"C++" file lock
which is just as I expected.
Perhaps there is a bettter language way to express what you meant? Maybe
using < stuff> angle brackets, that is,
or a fresh line as I hope I have done here.
 
O

osmium

osmium said:
Sherm Pendley said:
[email protected] (Richard) said:
[Please do not mail me a copy of your followup]

barcaroller <[email protected]> spake the secret code
<[email protected]> thusly:

I've googled "C++ file locking" and similar phrases. Try it, and
you'll see what I mean. Your link is exactly what I was looking for.
Thank you.

I googled "boost file lock". In general, I've found that "C++" isn't
a good term for google.

Its a bit like searching for my favorite band: "The Who".

Google gives better results if one uses quotation marks, i.e. search
for '"C++" file lock' rather than 'C++ file lock'.

I get 2.1e6 hits for
C++ file lock
and i get 2.1e6 hits for
"C++" file lock
which is just as I expected.
Perhaps there is a bettter language way to express what you meant? Maybe
using < stuff> angle brackets, that is,
or a fresh line as I hope I have done here.

language was meant to be meta-langauge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top