| author | |
| committer | |
| log | e06052f201a63edd772ffade74551d159c7a7784 |
| tree | 9fbe3f52abd34969cea3f9b328257289f41594c8 |
| parent | 2b90e2c2841e805ed1a1c3d16da96eb2fb8cd97d |
| signature |
* Added fseeki64.c from mingw-w64 9.0.0. This file was missing in Zig distribution. This file contains implementation for _fseeki64 and _ftelli64 functions.
4 files changed, 68 insertions(+), 0 deletions(-)
lib/libc/mingw/stdio/fseeki64.c created+50| ... | @@ -0,0 +1,50 @@ | ||
| 1 | /** | ||
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | ||
| 3 | * This file is part of the mingw-w64 runtime package. | ||
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | ||
| 5 | */ | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <io.h> | ||
| 8 | #include <errno.h> | ||
| 9 | |||
| 10 | #if !defined(__arm__) && !defined(__aarch64__) /* we have F_ARM_ANY(_fseeki64) in msvcrt.def.in */ | ||
| 11 | int __cdecl _fseeki64(FILE* stream, __int64 offset, int whence) | ||
| 12 | { | ||
| 13 | fpos_t pos; | ||
| 14 | if (whence == SEEK_CUR) | ||
| 15 | { | ||
| 16 | /* If stream is invalid, fgetpos sets errno. */ | ||
| 17 | if (fgetpos (stream, &pos)) | ||
| 18 | return (-1); | ||
| 19 | pos += (fpos_t) offset; | ||
| 20 | } | ||
| 21 | else if (whence == SEEK_END) | ||
| 22 | { | ||
| 23 | /* If writing, we need to flush before getting file length. */ | ||
| 24 | fflush (stream); | ||
| 25 | pos = (fpos_t) (_filelengthi64 (_fileno (stream)) + offset); | ||
| 26 | } | ||
| 27 | else if (whence == SEEK_SET) | ||
| 28 | pos = (fpos_t) offset; | ||
| 29 | else | ||
| 30 | { | ||
| 31 | errno = EINVAL; | ||
| 32 | return (-1); | ||
| 33 | } | ||
| 34 | return fsetpos (stream, &pos); | ||
| 35 | } | ||
| 36 | |||
| 37 | int __cdecl (*__MINGW_IMP_SYMBOL(_fseeki64))(FILE*, __int64, int) = _fseeki64; | ||
| 38 | #endif /* !defined(__arm__) && !defined(__aarch64__) */ | ||
| 39 | |||
| 40 | __int64 __cdecl _ftelli64(FILE* stream) | ||
| 41 | { | ||
| 42 | fpos_t pos; | ||
| 43 | if (fgetpos (stream, &pos)) | ||
| 44 | return -1LL; | ||
| 45 | else | ||
| 46 | return (__int64) pos; | ||
| 47 | } | ||
| 48 | |||
| 49 | __int64 __cdecl (*__MINGW_IMP_SYMBOL(_ftelli64))(FILE*) = _ftelli64; | ||
| 50 | |||
src/mingw.zig+1| ... | @@ -857,6 +857,7 @@ const mingwex_generic_src = [_][]const u8{ | ... | @@ -857,6 +857,7 @@ const mingwex_generic_src = [_][]const u8{ |
| 857 | "stdio" ++ path.sep_str ++ "fopen64.c", | 857 | "stdio" ++ path.sep_str ++ "fopen64.c", |
| 858 | "stdio" ++ path.sep_str ++ "fseeko32.c", | 858 | "stdio" ++ path.sep_str ++ "fseeko32.c", |
| 859 | "stdio" ++ path.sep_str ++ "fseeko64.c", | 859 | "stdio" ++ path.sep_str ++ "fseeko64.c", |
| 860 | "stdio" ++ path.sep_str ++ "fseeki64.c", | ||
| 860 | "stdio" ++ path.sep_str ++ "fsetpos64.c", | 861 | "stdio" ++ path.sep_str ++ "fsetpos64.c", |
| 861 | "stdio" ++ path.sep_str ++ "ftello.c", | 862 | "stdio" ++ path.sep_str ++ "ftello.c", |
| 862 | "stdio" ++ path.sep_str ++ "ftello64.c", | 863 | "stdio" ++ path.sep_str ++ "ftello64.c", |
test/standalone.zig+3| ... | @@ -36,6 +36,9 @@ pub fn addCases(cases: *tests.StandaloneContext) void { | ... | @@ -36,6 +36,9 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 36 | } | 36 | } |
| 37 | cases.addBuildFile("test/standalone/c_compiler/build.zig", .{ .build_modes = true, .cross_targets = true }); | 37 | cases.addBuildFile("test/standalone/c_compiler/build.zig", .{ .build_modes = true, .cross_targets = true }); |
| 38 | 38 | ||
| 39 | if (std.Target.current.os.tag == .windows) { | ||
| 40 | cases.addC("test/standalone/issue_9402/main.zig"); | ||
| 41 | } | ||
| 39 | // Try to build and run a PIE executable. | 42 | // Try to build and run a PIE executable. |
| 40 | if (std.Target.current.os.tag == .linux) { | 43 | if (std.Target.current.os.tag == .linux) { |
| 41 | cases.addBuildFile("test/standalone/pie/build.zig", .{}); | 44 | cases.addBuildFile("test/standalone/pie/build.zig", .{}); |
test/standalone/issue_9402/main.zig created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | const FILE = extern struct { | ||
| 2 | dummy_field: u8, | ||
| 3 | }; | ||
| 4 | |||
| 5 | extern fn _ftelli64([*c]FILE) i64; | ||
| 6 | extern fn _fseeki64([*c]FILE, i64, c_int) c_int; | ||
| 7 | |||
| 8 | pub export fn main(argc: c_int, argv: **u8) c_int { | ||
| 9 | _ = argv; | ||
| 10 | _ = argc; | ||
| 11 | _ = _ftelli64(null); | ||
| 12 | _ = _fseeki64(null, 123, 2); | ||
| 13 | return 0; | ||
| 14 | } | ||