| ... | @@ -48,6 +48,7 @@ error PathNotFound; | ... | @@ -48,6 +48,7 @@ error PathNotFound; |
| 48 | error OutOfMemory; | 48 | error OutOfMemory; |
| 49 | error Unseekable; | 49 | error Unseekable; |
| 50 | error EndOfFile; | 50 | error EndOfFile; |
| | 51 | error FilePosLargerThanPointerRange; |
| 51 | | 52 | |
| 52 | pub fn getStdErr() -> %File { | 53 | pub fn getStdErr() -> %File { |
| 53 | const handle = if (is_windows) | 54 | const handle = if (is_windows) |
| ... | @@ -204,6 +205,15 @@ pub const File = struct { | ... | @@ -204,6 +205,15 @@ pub const File = struct { |
| 204 | }; | 205 | }; |
| 205 | } | 206 | } |
| 206 | }, | 207 | }, |
| | 208 | Os.windows => { |
| | 209 | if (system.SetFilePointerEx(self.handle, amount, null, system.FILE_CURRENT) == 0) { |
| | 210 | const err = system.GetLastError(); |
| | 211 | return switch (err) { |
| | 212 | system.ERROR.INVALID_PARAMETER => error.BadFd, |
| | 213 | else => os.unexpectedErrorWindows(err), |
| | 214 | }; |
| | 215 | } |
| | 216 | }, |
| 207 | else => @compileError("unsupported OS"), | 217 | else => @compileError("unsupported OS"), |
| 208 | } | 218 | } |
| 209 | } | 219 | } |
| ... | @@ -211,7 +221,8 @@ pub const File = struct { | ... | @@ -211,7 +221,8 @@ pub const File = struct { |
| 211 | pub fn seekTo(self: &File, pos: usize) -> %void { | 221 | pub fn seekTo(self: &File, pos: usize) -> %void { |
| 212 | switch (builtin.os) { | 222 | switch (builtin.os) { |
| 213 | Os.linux, Os.macosx, Os.ios => { | 223 | Os.linux, Os.macosx, Os.ios => { |
| 214 | const result = system.lseek(self.handle, @bitCast(isize, pos), system.SEEK_SET); | 224 | const ipos = try math.cast(isize, pos); |
| | 225 | const result = system.lseek(self.handle, ipos, system.SEEK_SET); |
| 215 | const err = system.getErrno(result); | 226 | const err = system.getErrno(result); |
| 216 | if (err > 0) { | 227 | if (err > 0) { |
| 217 | return switch (err) { | 228 | return switch (err) { |
| ... | @@ -224,6 +235,16 @@ pub const File = struct { | ... | @@ -224,6 +235,16 @@ pub const File = struct { |
| 224 | }; | 235 | }; |
| 225 | } | 236 | } |
| 226 | }, | 237 | }, |
| | 238 | Os.windows => { |
| | 239 | const ipos = try math.cast(isize, pos); |
| | 240 | if (system.SetFilePointerEx(self.handle, ipos, null, system.FILE_BEGIN) == 0) { |
| | 241 | const err = system.GetLastError(); |
| | 242 | return switch (err) { |
| | 243 | system.ERROR.INVALID_PARAMETER => error.BadFd, |
| | 244 | else => os.unexpectedErrorWindows(err), |
| | 245 | }; |
| | 246 | } |
| | 247 | }, |
| 227 | else => @compileError("unsupported OS: " ++ @tagName(builtin.os)), | 248 | else => @compileError("unsupported OS: " ++ @tagName(builtin.os)), |
| 228 | } | 249 | } |
| 229 | } | 250 | } |
| ... | @@ -245,6 +266,25 @@ pub const File = struct { | ... | @@ -245,6 +266,25 @@ pub const File = struct { |
| 245 | } | 266 | } |
| 246 | return result; | 267 | return result; |
| 247 | }, | 268 | }, |
| | 269 | Os.windows => { |
| | 270 | var pos : system.LARGE_INTEGER = undefined; |
| | 271 | if (system.SetFilePointerEx(self.handle, 0, &pos, system.FILE_CURRENT) == 0) { |
| | 272 | const err = system.GetLastError(); |
| | 273 | return switch (err) { |
| | 274 | system.ERROR.INVALID_PARAMETER => error.BadFd, |
| | 275 | else => os.unexpectedErrorWindows(err), |
| | 276 | }; |
| | 277 | } |
| | 278 | |
| | 279 | assert(pos >= 0); |
| | 280 | if (@sizeOf(@typeOf(pos)) > @sizeOf(usize)) { |
| | 281 | if (pos > @maxValue(usize)) { |
| | 282 | return error.FilePosLargerThanPointerRange; |
| | 283 | } |
| | 284 | } |
| | 285 | |
| | 286 | return usize(pos); |
| | 287 | }, |
| 248 | else => @compileError("unsupported OS"), | 288 | else => @compileError("unsupported OS"), |
| 249 | } | 289 | } |
| 250 | } | 290 | } |