Discussion:
What is the share mode for fopen()?
(too old to reply)
Rover
2009-11-03 00:30:01 UTC
Permalink
Hi all,

I know there is a function called _fsopen() that allows one to specify the
file sharing mode.

Does anyone know what is the assumed file sharing mode when one calls
fopen()? What is the equivalent to CreateFile's share mode value?

My experiments allow me to open two files at the same time in two different
process irrespective of reading or writing. But I have not tried to write or
read from them.

Thanks.

Rover
Alex Blekhman
2009-11-03 09:40:59 UTC
Permalink
Post by Rover
I know there is a function called _fsopen() that allows one to
specify the file sharing mode.
Does anyone know what is the assumed file sharing mode when one
calls fopen()? What is the equivalent to CreateFile's share mode
value?
You could just debug the `fopen' call. VS ships with the source
code for CRT library. `fopen' is a mere wrapper over _fsopen(...,
_SH_DENYNO) call.

Alex
Leon
2009-11-15 05:43:35 UTC
Permalink
Hi Alex,

Thanks for the advice.

So without proper concurrency control and file locking, multiple users of a
file can use fopen() to open the file but their access will corrupt the file
or retrieving corrupted data much like failure to control access to a share
resource in MT programming. Is that what will happen?

Leon
Post by Rover
I know there is a function called _fsopen() that allows one to specify
the file sharing mode.
Does anyone know what is the assumed file sharing mode when one calls
fopen()? What is the equivalent to CreateFile's share mode value?
You could just debug the `fopen' call. VS ships with the source code for
CRT library. `fopen' is a mere wrapper over _fsopen(..., _SH_DENYNO) call.
Alex
Alex Blekhman
2009-11-15 12:02:30 UTC
Permalink
Post by Leon
So without proper concurrency control and file locking, multiple
users of a file can use fopen() to open the file but their
access will corrupt the file or retrieving corrupted data much
like failure to control access to a share resource in MT
programming. Is that what will happen?
Exactly. SH_DENYNO flag permits read and write access to a file.
Without proper synchronization you'll corrupt a file.

Alex

Loading...