On 10/12/2011 06:04, Pau Garcia i Quiles wrote:
> Hi,
>
> I am porting to Windows a Unix application that manages large files ( > 2
> GB). On Unix, this application already uses _FILE_OFFSET_BITS to support
> large files on 32-bit.
>
> Given that MinGW-W64 recently gained _FILE_OFFSET_BITS support, I downloaded
> x86_64-w64-mingw32-gcc-4.6.2-stdthread_rubenvb.7z (64-bit) and
> i686-w64-mingw32-gcc-4.6.2-stdthread_rubenvb.7z (32-bit) and tried a minimal
> test (attached) :
>
> mingwlfstest.c
> --8<---
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/stat.h>
>
> int main(int argc, char* argv[]) {
> off_t tmp;
> struct stat s;
>
> printf("void* size: %u bits\n", 8*sizeof(void*));
> printf("int size: %u bits\n", 8*sizeof(int));
> printf("off_t size: %u bits\n", 8*sizeof(tmp));
> printf("float size: %u bits\n", 8*sizeof(float));
> printf("double size: %u bits\n", 8*sizeof(double));
> printf("struct stat size: %u bits\n", 8*sizeof(s));
> printf("stat.st_size size: %u bits\n", 8*sizeof(s.st_size));
>
> return 0;
> }
> --8<---
>
> Makefile
> --8<---
> CC = gcc
> CFLAGS = -g
>
> all: mingwlfstest-withlfs mingwlfstest-withoutlfs
>
> mingwlfstest-withlfs: mingwlfstest-withlfs.o
> $(CC) $(LDFLAGS) -o $@ $^
>
> mingwlfstest-withlfs.o: mingwlfstest.c
> $(CC) $(CFLAGS) -c -D_FILE_OFFSET_BITS=64 -o $@ $<
>
> mingwlfstest-withoutlfs: mingwlfstest-withoutlfs.o
> $(CC) $(LDFLAGS) -o $@ $^
>
> mingwlfstest-withoutlfs.o: mingwlfstest.c
> $(CC) $(CFLAGS) -c -o $@ $<
>
> clean:
> del /f /q mingwlfstest-withlfs.exe mingwlfstest-withlfs.o
> mingwlfstest-withoutlfs.exe mingwlfstest-withoutlfs.o
>
> .PHONY: clean
> --8<---
>
> Output from 32-bit executable on Windows 7 64-bit:
>
> --8<---
> C:\blah\mingwlfs>mingwlfstest-withoutlfs.exe
> void* size: 32 bits
> int size: 32 bits
> off_t size: 32 bits <=======
> float size: 32 bits
> double size: 64 bits
> struct stat size: 288 bits
> stat.st_size size: 32 bits <=======
>
> C:\\blah\mingwlfs>mingwlfstest-withlfs.exe
> void* size: 32 bits
> int size: 32 bits
> off_t size: 64 bits <=======
> float size: 32 bits
> double size: 64 bits
> struct stat size: 288 bits
> stat.st_size size: 32 bits <=======
> --8<---
>
>
> Output from 64-bit executable on Windows 7 64-bit:
>
> --8<---
> C:\blah\mingwlfs>mingwlfstest-withoutlfs.exe
> void* size: 64 bits
> int size: 32 bits
> off_t size: 32 bits <=======
> float size: 32 bits
> double size: 64 bits
> struct stat size: 384 bits
> stat.st_size size: 32 bits <=======
>
> C:\blah\mingwlfs>mingwlfstest-withlfs.exe
> void* size: 64 bits
> int size: 32 bits
> off_t size: 64 bits <=======
> float size: 32 bits
> double size: 64 bits
> struct stat size: 384 bits
> stat.st_size size: 32 bits <=======
> --8<---
>
> Where st.st_size is an off_t (see struct stat here:
> http://linux.die.net/man/2/stat )
>
> When _FILE_OFFSET_BITS=64 is defined, I would expect off_t to be 64-bit
> always no matter if it is outside or inside a struct stat (i.e. even in the
> case of stat.st_size)
>
> On Linux, this works as expected: off_t is always 64-bit when
> _FILE_OFFSET_BITS=64 is defined:
>
> Output from 32-bit executable on 32-bit Linux:
> --8<---
> pgquiles@sid32:~/mingwlfs$ ./mingwlfstest-withoutlfs
> void* size: 32 bits
> int size: 32 bits
> off_t size: 32 bits
> float size: 32 bits
> double size: 64 bits
> struct stat size: 704 bits
> stat.st_size size: 32 bits
>
> pgquiles@sid32:~/mingwlfs$ ./mingwlfstest-withlfs
> void* size: 32 bits
> int size: 32 bits
> off_t size: 64 bits
> float size: 32 bits
> double size: 64 bits
> struct stat size: 768 bits
> stat.st_size size: 64 bits
> --8<---
>
> Output from 64-bit executable on 64-bit Linux:
> --8<---
> pgquiles@nattyserver:~/mingwlfs$ ./mingwlfstest-withoutlfs
> void* size: 64 bits
> int size: 32 bits
> off_t size: 64 bits
> float size: 32 bits
> double size: 64 bits
> struct stat size: 1152 bits
> stat.st_size size: 64 bits
>
> pgquiles@nattyserver:~/mingwlfs$ ./mingwlfstest-withlfs
> void* size: 64 bits
> int size: 32 bits
> off_t size: 64 bits
> float size: 32 bits
> double size: 64 bits
> struct stat size: 1152 bits
> stat.st_size size: 64 bits
> --8<---
>
> Am I doing something wrong? Is this a bug in MinGW-W64's implementation of
> _FILE_OFFSET_BITS?
> Yes, looks like I forgot the part about stat. Try this patch: Index: trunk/mingw-w64-headers/crt/_mingw_stat64.h =================================================================== --- trunk/mingw-w64-headers/crt/_mingw_stat64.h (revision 4539) +++ trunk/mingw-w64-headers/crt/_mingw_stat64.h (working copy) @@ -92,5 +92,10 @@ #define stat64 _stat64 /* for POSIX */ #define fstat64 _fstat64 /* for POSIX */ + +#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64) +#define stat _stat64 +#endif + #define _STAT_DEFINED #endif /* _STAT_DEFINED */
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
