On Wed, 4 Nov 2020 13:53:28 +0100, R.Wieser wrote:
I've got a small program which rewrites the contents of a textfile. I'm
using "fopen" for both the source as well as the target file, reading lines >> from the first and writing them to the second.
The problem is that when both have the same name the file is destroyed. :-(( >>
To fix that I've been looking for an "exclusive read" open mode (so that
opening the targetfile would error-out). The thing is that Windows doesn't >> seem to offer it :
It does offer an "x" modifier, but that one only works on writing.
I've also found a reference to "flock", but that doesn't seem to be part of >> the CRTDLL.DLL on XPsp3 .
How do I use "fopen" (or a similar crtdll function) to get an exclusive read >> lock ?
Not possible using `fopen()`. Use `fsopen()` instead. `fopen()` is simply
not share aware.
`fopen()` uses `_SH_DENYNO` sharing flag no matter what. That flag
translates to Windows' `FILE_SHARE_READ` and `FILE_SHARE_WRITE`.
AFAIK you don't need a read lock for file access (see a database course.)
|Location:||Huddersfield, West Yorkshire, UK|
|Nodes:||8 (1 / 7)|