[Issue 18017] [External] [DMC] File.size() uses a 32-bit signed integer for size internally (gives wrong results for files over ≈2.1 GB)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 28 17:42:16 UTC 2017


https://issues.dlang.org/show_bug.cgi?id=18017

--- Comment #2 from krzaq <issues.dlang.org.kq.ajsx at krzaq.cc> ---
Getting -m64 to work requires non-zero effort and even then isn't hassle-free.
I used this as a workaround instead:

ulong getFileSize(const string name)
{
    import std.utf;
    import core.sys.windows.windows;
    //import core.stdc.
        HANDLE hFile = CreateFile(name.toUTF16z, GENERIC_READ, 
        FILE_SHARE_READ, NULL, OPEN_EXISTING, 
        FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile==INVALID_HANDLE_VALUE){
        return -1; // error condition, could call GetLastError to find out more
    }

    LARGE_INTEGER size;
    if (!GetFileSizeEx(hFile, &size))
    {
        CloseHandle(hFile);
        return -1; // error condition, could call GetLastError to find out more
    }

    CloseHandle(hFile);
    return size.QuadPart;
}

--


More information about the Digitalmars-d-bugs mailing list