What is the difference between _SH_SECURE and _SH_DENYWR

_SH_DENYWR rejects any other attempt to open the file with write permissions (access violation) _SH_SECURE Sets the safe mode (shared reading, exclusive write access)

_SH_SECURE seems to be newer, based on the fact that the documents seem to mask it or lower it depending on where you look. There is almost no information about the network that I could find on it.

How do they differ from each other?

+4
source share
1 answer

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 mapped to FILE_SHARE_READ . Otherwise, it displays 0 (exclusive access).

The contrast is _SH_DENYWR , which is always mapped to FILE_SHARE_READ .

The corresponding portion of the CRT source code (lines 269-301 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); } 
+2
source

Source: https://habr.com/ru/post/1401823/


All Articles