Bug 21657 – MmFile cannot map empty files

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2021-02-22T13:37:46Z
Last change time
2024-12-01T16:38:29Z
Assigned to
No Owner
Creator
deadalnix
Moved to GitHub: phobos#10458 →

Comments

Comment #0 by deadalnix — 2021-02-22T13:37:46Z
First, let's create an empty file: $ touch me Now let's run the following sample code: int main(string[]) { import std.mmfile; scope f = new MmFile("me"); return 0; } It fails with the following error: std.exception.ErrnoException@std/mmfile.d(351): Could not map file me (Invalid argument) Now, let's add some content to our file $ echo love > me Running the program again now works as expected.
Comment #1 by wolframw — 2021-03-13T10:29:16Z
Windows cannot map empty files. The MSDN doc for CreateFileMappingW [1] says: > An attempt to map a file with a length of 0 (zero) fails with an error code > of ERROR_FILE_INVALID. Applications should test for files with a length of > 0 (zero) and reject those files. [1] https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-createfilemappingw
Comment #2 by robert.schadek — 2024-12-01T16:38:29Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10458 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB