diff options
Diffstat (limited to 'std')
| -rw-r--r-- | std/io.zig | 31 | ||||
| -rw-r--r-- | std/os/windows/index.zig | 3 |
2 files changed, 25 insertions, 9 deletions
diff --git a/std/io.zig b/std/io.zig index 02d96489ad..64946b28b4 100644 --- a/std/io.zig +++ b/std/io.zig @@ -253,17 +253,30 @@ pub const File = struct { } pub fn getEndPos(self: &File) -> %usize { - var stat: system.Stat = undefined; - const err = system.getErrno(system.fstat(self.handle, &stat)); - if (err > 0) { - return switch (err) { - system.EBADF => error.BadFd, - system.ENOMEM => error.OutOfMemory, - else => os.unexpectedErrorPosix(err), + if (is_posix) { + var stat: system.Stat = undefined; + const err = system.getErrno(system.fstat(self.handle, &stat)); + if (err > 0) { + return switch (err) { + system.EBADF => error.BadFd, + system.ENOMEM => error.OutOfMemory, + else => os.unexpectedErrorPosix(err), + } } - } - return usize(stat.size); + return usize(stat.size); + } else if (is_windows) { + var file_size: system.LARGE_INTEGER = undefined; + if (system.GetFileSizeEx(self.handle, &file_size) == 0) { + const err = system.GetLastError(); + return switch (err) { + else => os.unexpectedErrorWindows(err), + }; + } + return @bitCast(usize, file_size); + } else { + unreachable; + } } pub fn read(self: &File, buffer: []u8) -> %usize { diff --git a/std/os/windows/index.zig b/std/os/windows/index.zig index a398deb0b3..913cc79801 100644 --- a/std/os/windows/index.zig +++ b/std/os/windows/index.zig @@ -46,6 +46,8 @@ pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuf pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) -> BOOL; +pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL; + pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD; pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE, @@ -115,6 +117,7 @@ pub const ULONG_PTR = usize; pub const UNICODE = false; pub const WCHAR = u16; pub const WORD = u16; +pub const LARGE_INTEGER = i64; pub const TRUE = 1; pub const FALSE = 0; |
