mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 08:33:06 +00:00
Implemented windows versions of seekTo and getPos
This commit is contained in:
parent
0aae96b5f0
commit
90714a3831
30
std/io.zig
30
std/io.zig
@ -204,6 +204,15 @@ pub const File = struct {
|
||||
};
|
||||
}
|
||||
},
|
||||
Os.windows => {
|
||||
if (system.SetFilePointerEx(self.handle, amount, null, system.FILE_CURRENT) == 0) {
|
||||
const err = system.GetLastError();
|
||||
return switch (err) {
|
||||
system.ERROR.INVALID_PARAMETER => error.BadFd,
|
||||
else => os.unexpectedErrorPosix(err),
|
||||
};
|
||||
}
|
||||
},
|
||||
else => @compileError("unsupported OS"),
|
||||
}
|
||||
}
|
||||
@ -224,6 +233,15 @@ pub const File = struct {
|
||||
};
|
||||
}
|
||||
},
|
||||
Os.windows => {
|
||||
if (system.SetFilePointerEx(self.handle, @bitCast(isize, pos), null, system.FILE_BEGIN) == 0) {
|
||||
const err = system.GetLastError();
|
||||
return switch (err) {
|
||||
system.ERROR.INVALID_PARAMETER => error.BadFd,
|
||||
else => os.unexpectedErrorWindows(err),
|
||||
};
|
||||
}
|
||||
},
|
||||
else => @compileError("unsupported OS: " ++ @tagName(builtin.os)),
|
||||
}
|
||||
}
|
||||
@ -245,6 +263,18 @@ pub const File = struct {
|
||||
}
|
||||
return result;
|
||||
},
|
||||
Os.windows => {
|
||||
var pos : usize = undefined;
|
||||
if (system.SetFilePointerEx(self.handle, 0, @ptrCast(system.PLARGE_INTEGER, &pos), system.FILE_CURRENT) == 0) {
|
||||
const err = system.GetLastError();
|
||||
return switch (err) {
|
||||
system.ERROR.INVALID_PARAMETER => error.BadFd,
|
||||
else => os.unexpectedErrorWindows(err),
|
||||
};
|
||||
}
|
||||
|
||||
return pos;
|
||||
},
|
||||
else => @compileError("unsupported OS"),
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,9 @@ pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: LPVO
|
||||
in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD,
|
||||
in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn SetFilePointerEx(in_fFile: HANDLE, in_liDistanceToMove: LARGE_INTEGER,
|
||||
out_opt_ldNewFilePointer: ?PLARGE_INTEGER, in_dwMoveMethod: DWORD) -> BOOL;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) -> BOOL;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD);
|
||||
@ -126,6 +129,7 @@ pub const UNICODE = false;
|
||||
pub const WCHAR = u16;
|
||||
pub const WORD = u16;
|
||||
pub const LARGE_INTEGER = i64;
|
||||
pub const PLARGE_INTEGER = &LARGE_INTEGER;
|
||||
|
||||
pub const TRUE = 1;
|
||||
pub const FALSE = 0;
|
||||
@ -289,3 +293,7 @@ pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4;
|
||||
pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32;
|
||||
pub const MOVEFILE_REPLACE_EXISTING = 1;
|
||||
pub const MOVEFILE_WRITE_THROUGH = 8;
|
||||
|
||||
pub const FILE_BEGIN = 0;
|
||||
pub const FILE_CURRENT = 1;
|
||||
pub const FILE_END = 2;
|
Loading…
Reference in New Issue
Block a user