#705 struct __stat64 -- wrong size for _wstat64

Known_bugs
closed-fixed
Danny Smith
2005-01-17
2005-01-14
Doug Currie
No

The code below demonstrates that MinGW and WinXP differ
in their layout of struct __stat64.

sizeof(struct __stat64) returns 48
whereas _wstat64 writes 56 bytes.

$ gcc --version
gcc.exe (GCC) 3.4.2 (mingw-special)

WinXP SP 2

__MINGW32_VERSION 3.5

(but I looked at 3.7 and the definition of struct
__stat64 looks the same)

e

#define __MSVCRT_VERSION__ 0x0700
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main( int argc, char **argv )
{
char buf[128];
int i, j;

memset( buf, -1, sizeof(buf) );

_wstat64( L"stat_test.c", (struct __stat64 *)buf );

for (i = sizeof(buf); i > 0; )
{
if (buf[--i] != -1) break;
}

memset( buf, 0x5A, sizeof(buf) );

_wstat64( L"stat_test.c", (struct __stat64 *)buf );

for (j = sizeof(buf); j > 0; )
{
if (buf[--j] != 0x5A) break;
}

printf("sizeof(struct __stat64) is %d\n",
sizeof(struct __stat64));
printf("_wstat64 wrote a non -1 to %d\n", i);
printf("_wstat64 wrote a non 5A to %d\n", j);

return 0;
}

Discussion

  • Danny Smith
    Danny Smith
    2005-01-16

    • assigned_to: nobody --> dannysmith
     
  • Danny Smith
    Danny Smith
    2005-01-17

    Logged In: YES
    user_id=11494

    I can't find any documentation on the st_size member of
    __stat64, but given your test case it must be a 64-bit type
    (this makes sizeof __stat64 56 bytes and also produce
    correct results for the the time members), so I have changed
    it to __int64 in CVS.

    Danny

     
  • Danny Smith
    Danny Smith
    2005-01-17

    • status: open --> closed-fixed