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);
}