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 {...@@ -253,17 +253,30 @@ pub const File = struct {
253 }253 }
254254
255 pub fn getEndPos(self: &File) -> %usize {255 pub fn getEndPos(self: &File) -> %usize {
256 var stat: system.Stat = undefined;256 if (is_posix) {
257 const err = system.getErrno(system.fstat(self.handle, &stat));257 var stat: system.Stat = undefined;
258 if (err > 0) {258 const err = system.getErrno(system.fstat(self.handle, &stat));
259 return switch (err) {259 if (err > 0) {
260 system.EBADF => error.BadFd,260 return switch (err) {
261 system.ENOMEM => error.OutOfMemory,261 system.EBADF => error.BadFd,
262 else => os.unexpectedErrorPosix(err),262 system.ENOMEM => error.OutOfMemory,
263 else => os.unexpectedErrorPosix(err),
264 }
263 }265 }
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 }
267 }280 }
268281
269 pub fn read(self: &File, buffer: []u8) -> %usize {282 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...@@ -46,6 +46,8 @@ pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuf
4646
47pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) -> BOOL;47pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) -> BOOL;
4848
49pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL;
50
49pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;51pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;
5052
51pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,53pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,
...@@ -115,6 +117,7 @@ pub const ULONG_PTR = usize;...@@ -115,6 +117,7 @@ pub const ULONG_PTR = usize;
115pub const UNICODE = false;117pub const UNICODE = false;
116pub const WCHAR = u16;118pub const WCHAR = u16;
117pub const WORD = u16;119pub const WORD = u16;
120pub const LARGE_INTEGER = i64;
118121
119pub const TRUE = 1;122pub const TRUE = 1;
120pub const FALSE = 0;123pub const FALSE = 0;