From 55cd860ea3d86b2f9b1ee5857fde72e9e052e1a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 12 Jan 2021 11:49:05 +0100 Subject: [PATCH] Implement ThreadedFileEventDriver.truncate on Windows. --- source/eventcore/drivers/threadedfile.d | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/eventcore/drivers/threadedfile.d b/source/eventcore/drivers/threadedfile.d index 9058483..f9dd6c4 100644 --- a/source/eventcore/drivers/threadedfile.d +++ b/source/eventcore/drivers/threadedfile.d @@ -224,6 +224,26 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents) : EventDriverFil return; } on_finish(file, IOStatus.ok, 0); + } else version (Windows) { + import core.sys.windows.windows : FILE_BEGIN, HANDLE, INVALID_HANDLE_VALUE, + LARGE_INTEGER, SetFilePointerEx, SetEndOfFile; + import core.stdc.stdio : _get_osfhandle; + + auto h = () @trusted { return cast(HANDLE)_get_osfhandle(cast(int)file); } (); + if (h == INVALID_HANDLE_VALUE) { + on_finish(file, IOStatus.error, 0); + return; + } + LARGE_INTEGER ls = { QuadPart: size }; + if (!() @trusted { return SetFilePointerEx(h, ls, null, FILE_BEGIN); } ()) { + on_finish(file, IOStatus.error, 0); + return; + } + if (!() @trusted { return SetEndOfFile(h); } ()) { + on_finish(file, IOStatus.error, 0); + return; + } + on_finish(file, IOStatus.ok, 0); } else { on_finish(file, IOStatus.error, 0); }