Closed michal-z closed 2 years ago
PS: I should have read the source code first lol :)
FYI: at least on macOS the regular ftell() function returns a 64-bit value (long int). I tested by creating a 6000 1024 1024 bytes file and then:
FILE* fp = fopen("file.bin", "rb");
fseek(fp, 0, SEEK_END);
long int pos = ftell(fp);
fclose(fp);
printf("size: %ld\n", pos);
This prints:
size: 6291456000
I'd expect on Linux this also works, and that it's just Windows which is the outlier.
@floooh Thanks for the info. Yes, this looks like Windows only issue.
(I think the problem comes down to the fact that long
is 32-bit in msvc and 64-bit in other compilers, when compiling for x86_64).
Turned out that this is a zig cc bug/omission. zig cc uses mingw-w64 and mingw-w64 has implementation for _ftelli64, but zig cc did not expose it. This will be fixed on the zig cc side.
I hit a compile error when compiling with zig cc -
_ftelli64
is msvc thing so the check for it should be:Note. zig cc by default uses clang and mingw64 so it defines
__clang__
and__GNUC__
. On the other hand, cl-clang on Windows defines__clang__
and_MSC_VER
.