authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-11-10 14:36:03-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-11-10 14:36:03-05:00
log20c2dbdbd3847cfaa580878fca2566347a2f4733
treeade52bac91ed59d135e700fec593b74bf4623f2b
parent1ac46fac15953820948b77b94083828f84673641

add windows implementation of io.File.getEndPos


2 files changed, 25 insertions(+), 9 deletions(-)

std/io.zig+22-9
......@@ -253,17 +253,30 @@ pub const File = struct {
253253 }
254254
255255 pub fn getEndPos(self: &File) -> %usize {
256 var stat: system.Stat = undefined;
257 const err = system.getErrno(system.fstat(self.handle, &stat));
258 if (err > 0) {
259 return switch (err) {
260 system.EBADF => error.BadFd,
261 system.ENOMEM => error.OutOfMemory,
262 else => os.unexpectedErrorPosix(err),
256 if (is_posix) {
257 var stat: system.Stat = undefined;
258 const err = system.getErrno(system.fstat(self.handle, &stat));
259 if (err > 0) {
260 return switch (err) {
261 system.EBADF => error.BadFd,
262 system.ENOMEM => error.OutOfMemory,
263 else => os.unexpectedErrorPosix(err),
264 }
263265 }
264 }
265266
266 return usize(stat.size);
267 return usize(stat.size);
268 } else if (is_windows) {
269 var file_size: system.LARGE_INTEGER = undefined;
270 if (system.GetFileSizeEx(self.handle, &file_size) == 0) {
271 const err = system.GetLastError();
272 return switch (err) {
273 else => os.unexpectedErrorWindows(err),
274 };
275 }
276 return @bitCast(usize, file_size);
277 } else {
278 unreachable;
279 }
267280 }
268281
269282 pub fn read(self: &File, buffer: []u8) -> %usize {
std/os/windows/index.zig+3
......@@ -46,6 +46,8 @@ pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuf
4646
4747pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) -> BOOL;
4848
49pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL;
50
4951pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;
5052
5153pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,
......@@ -115,6 +117,7 @@ pub const ULONG_PTR = usize;
115117pub const UNICODE = false;
116118pub const WCHAR = u16;
117119pub const WORD = u16;
120pub const LARGE_INTEGER = i64;
118121
119122pub const TRUE = 1;
120123pub const FALSE = 0;