File needs to be closed on Windows but not on Posix, bug?

rumbu via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 7 05:19:01 PDT 2014


On Monday, 7 July 2014 at 11:17:35 UTC, Joakim 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.

In std.stdio, File(name, mode) is forwarded to _wfopen on Windows 
and to fopen on posix.

On Windows there are many mode flags supported by the _wfopen 
function (link above):

If you intend to delete the file immediately after closing it, 
you can use the "D" mode flag when instantiating the File struct.

-or-

You can write your own wrapper around CreateFile/Ex WinAPI 
function and use FILE_SHARE_DELETE for dwSharingMode; now you can 
safely delete the file without closing it even from another 
process.







More information about the Digitalmars-d-learn mailing list