File needs to be closed on Windows but not on Posix, bug?
Regan Heath via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 7 05:00:47 PDT 2014
On Mon, 07 Jul 2014 12:17:34 +0100, Joakim <dlang at joakim.airpost.net>
wrote:
> On Monday, 7 July 2014 at 10:19:01 UTC, Kagamin wrote:
>> See if stdio allows you to specify delete sharing when opening the file.
>
> I don't know what delete sharing is exactly, but the File constructor
> simply calls fopen and I don't see any option for the Windows fopen that
> seems to do it:
>
> http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx
The fopen variant that allows you to specify sharing is:
http://msdn.microsoft.com/en-us/library/8f30b0db.aspx
But it does not mention delete sharing there.
CreateFile allows sharing to be specified for delete however:
http://msdn.microsoft.com/en-gb/library/windows/desktop/aa363858(v=vs.85).aspx
So... you could:
- Call CreateFile giving you a "handle"
- Call _open_osfhandle to get a "file descriptor"
- Call _fdopen on the file descriptor to get a FILE* for it
But! I agree with Adam, leave it as a thin wrapper. Being a windows
programmer by trade I would expect the remove to fail, I would not expect
all my files to be opened with delete sharing enabled by default.
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d-learn
mailing list