authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-01-19 21:30:57+01:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-01-19 21:30:57+01:00
log90714a38311ec79500c0257670985bfe5d6c9a1b
tree2c7c7338b1392a4cd8063805f97092733340fc9e
parent0aae96b5f0a592ee3e2ff3607121740042878634

Implemented windows versions of seekTo and getPos


2 files changed, 38 insertions(+), 0 deletions(-)

std/io.zig+30
......@@ -204,6 +204,15 @@ pub const File = struct {
204204 };
205205 }
206206 },
207 Os.windows => {
208 if (system.SetFilePointerEx(self.handle, amount, null, system.FILE_CURRENT) == 0) {
209 const err = system.GetLastError();
210 return switch (err) {
211 system.ERROR.INVALID_PARAMETER => error.BadFd,
212 else => os.unexpectedErrorPosix(err),
213 };
214 }
215 },
207216 else => @compileError("unsupported OS"),
208217 }
209218 }
......@@ -224,6 +233,15 @@ pub const File = struct {
224233 };
225234 }
226235 },
236 Os.windows => {
237 if (system.SetFilePointerEx(self.handle, @bitCast(isize, pos), null, system.FILE_BEGIN) == 0) {
238 const err = system.GetLastError();
239 return switch (err) {
240 system.ERROR.INVALID_PARAMETER => error.BadFd,
241 else => os.unexpectedErrorWindows(err),
242 };
243 }
244 },
227245 else => @compileError("unsupported OS: " ++ @tagName(builtin.os)),
228246 }
229247 }
......@@ -245,6 +263,18 @@ pub const File = struct {
245263 }
246264 return result;
247265 },
266 Os.windows => {
267 var pos : usize = undefined;
268 if (system.SetFilePointerEx(self.handle, 0, @ptrCast(system.PLARGE_INTEGER, &pos), system.FILE_CURRENT) == 0) {
269 const err = system.GetLastError();
270 return switch (err) {
271 system.ERROR.INVALID_PARAMETER => error.BadFd,
272 else => os.unexpectedErrorWindows(err),
273 };
274 }
275
276 return pos;
277 },
248278 else => @compileError("unsupported OS"),
249279 }
250280 }
std/os/windows/index.zig+8
......@@ -74,6 +74,9 @@ pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: LPVO
7474 in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD,
7575 in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL;
7676
77pub extern "kernel32" stdcallcc fn SetFilePointerEx(in_fFile: HANDLE, in_liDistanceToMove: LARGE_INTEGER,
78 out_opt_ldNewFilePointer: ?PLARGE_INTEGER, in_dwMoveMethod: DWORD) -> BOOL;
79
7780pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) -> BOOL;
7881
7982pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD);
......@@ -126,6 +129,7 @@ pub const UNICODE = false;
126129pub const WCHAR = u16;
127130pub const WORD = u16;
128131pub const LARGE_INTEGER = i64;
132pub const PLARGE_INTEGER = &LARGE_INTEGER;
129133
130134pub const TRUE = 1;
131135pub const FALSE = 0;
......@@ -289,3 +293,7 @@ pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4;
289293pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32;
290294pub const MOVEFILE_REPLACE_EXISTING = 1;
291295pub const MOVEFILE_WRITE_THROUGH = 8;
296
297pub const FILE_BEGIN = 0;
298pub const FILE_CURRENT = 1;
299pub const FILE_END = 2;
\ No newline at end of file