add windows implementation of io.File.getEndPos
This commit is contained in:
parent
1ac46fac15
commit
20c2dbdbd3
31
std/io.zig
31
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 {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user