Bug 698783

Summary: MinGW doesn't provide _ftelli64()/_fseeki64()
Product: MuPDF Reporter: Tamir Evan <tamirevan>
Component: fitzAssignee: MuPDF bugs <mupdf-bugs>
Status: RESOLVED WORKSFORME    
Severity: normal CC: tamirevan
Priority: P4    
Version: master   
Hardware: PC   
OS: Windows 7   
Customer: Word Size: ---

Description Tamir Evan 2017-11-26 09:12:35 UTC
When I extract the source from mupdf-1.12-rc1-source.tar.gz , apply the fix I suggested in Bug 698782, and run, under MinGW (of mingw.org):

     make HAVE_GLUT=no

I get:

    [...]
        CC build/release/source/fitz/output.o
    source/fitz/output.c: In function 'file_seek':
    source/fitz/output.c:130:10: warning: implicit declaration of function '_fseeki64' [-Wimplicit-function-declaration]
      int n = _fseeki64(file, off, whence);
              ^~~~~~~~~
    source/fitz/output.c: In function 'file_tell':
    source/fitz/output.c:143:16: warning: implicit declaration of function '_ftelli64' [-Wimplicit-function-declaration]
      int64_t off = _ftelli64(file);
                    ^~~~~~~~~
    [...]
        CC build/release/source/fitz/stream-open.o
    source/fitz/stream-open.c: In function 'seek_file':
    source/fitz/stream-open.c:110:14: warning: implicit declaration of function '_fseeki64' [-Wimplicit-function-declaration]
      int64_t n = _fseeki64(state->file, offset, whence);
                  ^~~~~~~~~
    source/fitz/stream-open.c:117:13: warning: implicit declaration of function '_ftelli64' [-Wimplicit-function-declaration]
      stm->pos = _ftelli64(state->file);
                 ^~~~~~~~~
    [...]
    In file included from scripts/cmapdump.c:22:0:
    scripts/../source/fitz/output.c: In function 'file_seek':
    scripts/../source/fitz/output.c:130:10: warning: implicit declaration of function '_fseeki64' [-Wimplicit-function-declaration]
      int n = _fseeki64(file, off, whence);
              ^~~~~~~~~
    scripts/../source/fitz/output.c: In function 'file_tell':
    scripts/../source/fitz/output.c:143:16: warning: implicit declaration of function '_ftelli64' [-Wimplicit-function-declaration]
      int64_t off = _ftelli64(file);
                    ^~~~~~~~~
    scripts/../source/fitz/output.c: In function 'fz_new_output_with_path':
    scripts/../source/fitz/output.c:196:7: warning: implicit declaration of function 'fz_remove_utf8' [-Wimplicit-function-declaration]
       if (fz_remove_utf8(filename) < 0)
           ^~~~~~~~~~~~~~
    LINK build/release/scripts/cmapdump.exe
    build/release/scripts/cmapdump.o:cmapdump.c:(.text$file_tell+0xb): undefined reference to `_ftelli64'
    build/release/scripts/cmapdump.o:cmapdump.c:(.text$seek_file+0x3b): undefined reference to `_ftelli64'
    collect2.exe: error: ld returned 1 exit status
    make: *** [build/release/scripts/cmapdump.exe] Error 1

and the build stops.

Looking into it, it turns out that MinGW (of mingw.org) doesn't provide _ftelli64()/_fseeki64() (although Mingw-w64 does), nor ftello()/fseeko(). Instead, it provides ftello64()/fseeko64(), which seems to do the same thing.

A solution would be to do, in source/fitz/output.c, for _ftelli64:

    #ifdef __MINGW32__
	    int64_t off = ftello64(file);
    #elif defined(_WIN32) || defined(_WIN64)
	    int64_t off = _ftelli64(file);

and for _fseeki64:

    #ifdef __MINGW32__
	    int n = fseeko64(file, off, whence);
    #elif defined(_WIN32) || defined(_WIN64)
	    int n = _fseeki64(file, off, whence);

and do something equivalent in source/fitz/stream-open.c.
Comment 1 Tamir Evan 2018-04-05 07:50:50 UTC
Based on my conversation with Tor on March 23rd 2018 (https://ghostscript.com/mupdfirclogs/2018/03/23.html), I concede that the problem I reported here can be worked around by adding 'XCFLAGS+=-D_ftelli64=ftello64 XCFLAGS+=-D_fseeki64=fseeko64' to the invocation of make, when building under mingw.org's MinGW.

As this is the only case I know of with this problem (the Mingw-w64 based toolchains work fine as is), and a workaround exists, this bug could probably be resolved as some kind of 'won't fix'.
Comment 2 Tamir Evan 2019-07-16 02:10:41 UTC
As recent versions of the MinGW (of mingw.org) toolchain provide _ftelli64()/_fseeki64() (https://osdn.net/projects/mingw/ticket/38225#comment:3917:38225:1543954979), there is no need to work around it's absence anymore. Therefore, I am closing this bug report.