Web lists-archives.com

Re: [Mingw-users] I need a compatible stat64




On 05/01/16 15:56, Eli Zaretskii wrote:
>> Date: Mon, 4 Jan 2016 22:02:20 -0800
>> From: Greg Jung <gvjung@xxxxxxxxx>
>>
>> I'm building a program that uses a subroutine with a lot of file access,
>> several months back - compiling using mingw-w64 - I switched the use
>> of stat() to that of stat64() in order to get a 64-bit file size. This works
>> fine
>> in mingw-w64, cygwin, and linux but I find now it is invalid in this 
>> mingw. Can someone suggest a viable workaround? 
> 
> What version of the MinGW runtime do you have?
> 
> In any case, I think you want _stat64, not stat64.  Just look at
> what's in your sys/stat.h header file, and take it from there.

More specifically, unless you jump through a number of hoops to link
with one of MSVC's non-free runtime DLLs, you need to choose one of the
stat() function variants provided by MSVCRT.DLL, on your target host;
for all windows versions since Win98/WinNT4 onwards, that gives you the
choice of _stat(), (32-bit times, 32-bit file size), and _stati64(),
(32-bit times, 64-bit file size), and then, first appearing in Win2K,
_stat64(), (64-bit times, 64-bit file size).

So, since you need a 64-bit file size, it seems that either _stat64() or
_stati64() may suit, (with _stati64() having the better backward
compatibility to earlier host versions.  Do take care that, whichever
you choose, that you couple it with the appropriate variant of the _stat
structure declaration, or, as the attached program output (run on Win7
VM) shows, you will get garbage in the returned data fields.

And finally, don't be distracted by either _FILE_OFFSET_BITS=64, (which
is a GNU/Linuxism, and has absolutely no effect in MinGW), or by
Microsoft's _USE_32BIT_TIME_T brain damage, (which is irrelevant for the
*real* function entry points in MSVCRT.DLL).

-- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F
Checking for _stat()... yes
Analysing behaviour of function _stat()...

Content of returned[*] stat data structure is:--

0000  02 00 00 00 00 00 b6 81 01 00 00 00 00 00 aa aa  ................
0010  02 00 00 00 00 00 00 00 32 50 8c 56 32 50 8c 56  ........2P.V2P.V
0020  32 50 8c 56 aa aa aa aa aa aa aa aa aa aa aa aa  2P.V............
0030  aa aa aa aa aa aa aa aa                          ........

Interpreting as respectively _stat, and _stat32i64 return data,
the embedded file sizes and time stamp values are represented as:--

                                      _stat                _stat32i64
                   ------------------------  ------------------------
    Creation time:       0x00000000568c5032        0xffffffffaaaaaaaa
 Last access time:       0x00000000568c5032        0x00000000568c5032
  Last write time:       0x00000000568c5032        0xffffffffaaaaaaaa
        File size:       0x0000000000000000        0x568c5032568c5032
-----------------  ------------------------  ------------------------

When expressed as elapsed seconds since the beginning of 
the unix epoch, the above timestamp values represent:--

                         _stat (__time32_t)   _stat32i64 (__time32_t)
                   ------------------------  ------------------------
    Creation time:              +1452036146               -1431655766
 Last access time:              +1452036146               +1452036146
  Last write time:              +1452036146               -1431655766
-----------------  ------------------------  ------------------------

The decimal value equivalents for the above file sizes are:--

                            _stat (int32_t)      _stat32i64 (int64_t)
                   ------------------------  ------------------------
        File size:                       +0      +6236447761131917362
-----------------  ------------------------  ------------------------

Interpreting as respectively _stat64i32, and _stat64 return data,
the embedded file sizes and time stamp values are represented as:--

                                 _stat64i32                   _stat64
                   ------------------------  ------------------------
    Creation time:       0xaaaaaaaaaaaaaaaa        0xaaaaaaaaaaaaaaaa
 Last access time:       0x568c5032568c5032        0xaaaaaaaa568c5032
  Last write time:       0xaaaaaaaa568c5032        0xaaaaaaaaaaaaaaaa
        File size:       0x0000000000000000        0x568c5032568c5032
-----------------  ------------------------  ------------------------

When expressed as elapsed seconds since the beginning of 
the unix epoch, the above timestamp values represent:--

                    _stat64i32 (__time64_t)      _stat64 (__time64_t)
                   ------------------------  ------------------------
    Creation time:     -6148914691236517206      -6148914691236517206
 Last access time:     +6236447761131917362      -6148914692647792590
  Last write time:     -6148914692647792590      -6148914691236517206
-----------------  ------------------------  ------------------------

The decimal value equivalents for the above file sizes are:--

                       _stat64i32 (int32_t)         _stat64 (int64_t)
                   ------------------------  ------------------------
        File size:                       +0      +6236447761131917362
-----------------  ------------------------  ------------------------

Checking for _stat32()... no
_stat32() is not available in the current run time environment


Checking for _stat64()... yes
Analysing behaviour of function _stat64()...

Content of returned[*] stat data structure is:--

0000  02 00 00 00 00 00 b6 81 01 00 00 00 00 00 aa aa  ................
0010  02 00 00 00 aa aa aa aa 00 00 00 00 00 00 00 00  ................
0020  32 50 8c 56 00 00 00 00 32 50 8c 56 00 00 00 00  2P.V....2P.V....
0030  32 50 8c 56 00 00 00 00                          2P.V....

Interpreting as respectively _stat, and _stat32i64 return data,
the embedded file sizes and time stamp values are represented as:--

                                      _stat                _stat32i64
                   ------------------------  ------------------------
    Creation time:       0x00000000568c5032        0x00000000568c5032
 Last access time:       0x0000000000000000        0x00000000568c5032
  Last write time:       0x0000000000000000        0x0000000000000000
        File size:       0xffffffffaaaaaaaa        0x0000000000000000
-----------------  ------------------------  ------------------------

When expressed as elapsed seconds since the beginning of 
the unix epoch, the above timestamp values represent:--

                         _stat (__time32_t)   _stat32i64 (__time32_t)
                   ------------------------  ------------------------
    Creation time:              +1452036146               +1452036146
 Last access time:                       +0               +1452036146
  Last write time:                       +0                        +0
-----------------  ------------------------  ------------------------

The decimal value equivalents for the above file sizes are:--

                            _stat (int32_t)      _stat32i64 (int64_t)
                   ------------------------  ------------------------
        File size:              -1431655766                        +0
-----------------  ------------------------  ------------------------

Interpreting as respectively _stat64i32, and _stat64 return data,
the embedded file sizes and time stamp values are represented as:--

                                 _stat64i32                   _stat64
                   ------------------------  ------------------------
    Creation time:       0x00000000568c5032        0x00000000568c5032
 Last access time:       0x0000000000000000        0x00000000568c5032
  Last write time:       0x00000000568c5032        0x00000000568c5032
        File size:       0xffffffffaaaaaaaa        0x0000000000000000
-----------------  ------------------------  ------------------------

When expressed as elapsed seconds since the beginning of 
the unix epoch, the above timestamp values represent:--

                    _stat64i32 (__time64_t)      _stat64 (__time64_t)
                   ------------------------  ------------------------
    Creation time:              +1452036146               +1452036146
 Last access time:                       +0               +1452036146
  Last write time:              +1452036146               +1452036146
-----------------  ------------------------  ------------------------

The decimal value equivalents for the above file sizes are:--

                       _stat64i32 (int32_t)         _stat64 (int64_t)
                   ------------------------  ------------------------
        File size:              -1431655766                        +0
-----------------  ------------------------  ------------------------

Checking for _stat32i64()... no
_stat32i64() is not available in the current run time environment


Checking for _stat64i32()... no
_stat64i32() is not available in the current run time environment


Checking for _stati64()... yes
Analysing behaviour of function _stati64()...

Content of returned[*] stat data structure is:--

0000  02 00 00 00 00 00 b6 81 01 00 00 00 00 00 aa aa  ................
0010  02 00 00 00 aa aa aa aa 00 00 00 00 00 00 00 00  ................
0020  32 50 8c 56 32 50 8c 56 32 50 8c 56 aa aa aa aa  2P.V2P.V2P.V....
0030  aa aa aa aa aa aa aa aa                          ........

Interpreting as respectively _stat, and _stat32i64 return data,
the embedded file sizes and time stamp values are represented as:--

                                      _stat                _stat32i64
                   ------------------------  ------------------------
    Creation time:       0x00000000568c5032        0x00000000568c5032
 Last access time:       0x0000000000000000        0x00000000568c5032
  Last write time:       0x0000000000000000        0x00000000568c5032
        File size:       0xffffffffaaaaaaaa        0x0000000000000000
-----------------  ------------------------  ------------------------

When expressed as elapsed seconds since the beginning of 
the unix epoch, the above timestamp values represent:--

                         _stat (__time32_t)   _stat32i64 (__time32_t)
                   ------------------------  ------------------------
    Creation time:              +1452036146               +1452036146
 Last access time:                       +0               +1452036146
  Last write time:                       +0               +1452036146
-----------------  ------------------------  ------------------------

The decimal value equivalents for the above file sizes are:--

                            _stat (int32_t)      _stat32i64 (int64_t)
                   ------------------------  ------------------------
        File size:              -1431655766                        +0
-----------------  ------------------------  ------------------------

Interpreting as respectively _stat64i32, and _stat64 return data,
the embedded file sizes and time stamp values are represented as:--

                                 _stat64i32                   _stat64
                   ------------------------  ------------------------
    Creation time:       0xaaaaaaaa568c5032        0xaaaaaaaaaaaaaaaa
 Last access time:       0x0000000000000000        0x568c5032568c5032
  Last write time:       0x568c5032568c5032        0xaaaaaaaa568c5032
        File size:       0xffffffffaaaaaaaa        0x0000000000000000
-----------------  ------------------------  ------------------------

When expressed as elapsed seconds since the beginning of 
the unix epoch, the above timestamp values represent:--

                    _stat64i32 (__time64_t)      _stat64 (__time64_t)
                   ------------------------  ------------------------
    Creation time:     -6148914692647792590      -6148914691236517206
 Last access time:                       +0      +6236447761131917362
  Last write time:     +6236447761131917362      -6148914692647792590
-----------------  ------------------------  ------------------------

The decimal value equivalents for the above file sizes are:--

                       _stat64i32 (int32_t)         _stat64 (int64_t)
                   ------------------------  ------------------------
        File size:              -1431655766                        +0
-----------------  ------------------------  ------------------------


[*] In each case, the return data structure is filled with a
    repeating pattern of 0xaa bytes, before invoking the function
    which is to be analysed.  Any byte sequences which continue to
    exhibit this pattern, after the function has returned, may be
    assumed to have remained untouched during the function call.

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe