jkuhlmann / cgltf

:diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99
MIT License
1.44k stars 136 forks source link

_ftelli64 does not compile on Windows when using zig cc (clang, mingw64) #162

Closed michal-z closed 2 years ago

michal-z commented 2 years ago

I hit a compile error when compiling with zig cc - _ftelli64 is msvc thing so the check for it should be:

#if defined(_WIN32) && defined(_MSC_VER)

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.

floooh commented 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.

michal-z commented 2 years ago

@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).

michal-z commented 2 years ago

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.