_SH_DENYWR denies any other attempt to open a file with write permissions (share violation) _SH_SECURE Sets secure mode (shared read, exclusive write access)
The _SH_SECURE seems to be newer, based on the fact that the docs seem to gloss over it or omit it depending on where you look. There's almost no info on the 'net that I could find on it.
How are those any different?
The behavior of _SH_SECURE
depends on the access requested in the mode
argument to _fsopen()
/_wfsopen()
. If only read access is requested, then _SH_SECURE
maps to FILE_SHARE_READ
. Otherwise, it maps to 0
(exclusive access).
Contrast _SH_DENYWR
, which always maps to FILE_SHARE_READ
.
The relevant part of the CRT source code (lines 269-301 of open.c
in Visual Studio 2010) is as follows:
/*
* decode sharing flags
*/
switch ( shflag ) {
case _SH_DENYRW: /* exclusive access */
fileshare = 0L;
break;
case _SH_DENYWR: /* share read access */
fileshare = FILE_SHARE_READ;
break;
case _SH_DENYRD: /* share write access */
fileshare = FILE_SHARE_WRITE;
break;
case _SH_DENYNO: /* share read and write access */
fileshare = FILE_SHARE_READ | FILE_SHARE_WRITE;
break;
case _SH_SECURE: /* share read access only if read-only */
if (fileaccess == GENERIC_READ)
fileshare = FILE_SHARE_READ;
else
fileshare = 0L;
break;
default: /* error, bad shflag */
_doserrno = 0L; /* not an OS error */
*pfh = -1;
_VALIDATE_RETURN_ERRCODE(( "Invalid sharing flag" , 0 ), EINVAL);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With