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 {...@@ -204,6 +204,15 @@ pub const File = struct {
204 };204 };
205 }205 }
206 },206 },
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 },
207 else => @compileError("unsupported OS"),216 else => @compileError("unsupported OS"),
208 }217 }
209 }218 }
...@@ -224,6 +233,15 @@ pub const File = struct {...@@ -224,6 +233,15 @@ pub const File = struct {
224 };233 };
225 }234 }
226 },235 },
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 },
227 else => @compileError("unsupported OS: " ++ @tagName(builtin.os)),245 else => @compileError("unsupported OS: " ++ @tagName(builtin.os)),
228 }246 }
229 }247 }
...@@ -245,6 +263,18 @@ pub const File = struct {...@@ -245,6 +263,18 @@ pub const File = struct {
245 }263 }
246 return result;264 return result;
247 },265 },
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 },
248 else => @compileError("unsupported OS"),278 else => @compileError("unsupported OS"),
249 }279 }
250 }280 }
std/os/windows/index.zig+8
...@@ -74,6 +74,9 @@ pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: LPVO...@@ -74,6 +74,9 @@ pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: LPVO
74 in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD,74 in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD,
75 in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL;75 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
77pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) -> BOOL;80pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) -> BOOL;
7881
79pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD);82pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD);
...@@ -126,6 +129,7 @@ pub const UNICODE = false;...@@ -126,6 +129,7 @@ pub const UNICODE = false;
126pub const WCHAR = u16;129pub const WCHAR = u16;
127pub const WORD = u16;130pub const WORD = u16;
128pub const LARGE_INTEGER = i64;131pub const LARGE_INTEGER = i64;
132pub const PLARGE_INTEGER = &LARGE_INTEGER;
129133
130pub const TRUE = 1;134pub const TRUE = 1;
131pub const FALSE = 0;135pub const FALSE = 0;
...@@ -289,3 +293,7 @@ pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4;...@@ -289,3 +293,7 @@ pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4;
289pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32;293pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32;
290pub const MOVEFILE_REPLACE_EXISTING = 1;294pub const MOVEFILE_REPLACE_EXISTING = 1;
291pub const MOVEFILE_WRITE_THROUGH = 8;295pub 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