Web lists-archives.com

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

On Tue, Jan 5, 2016 at 11:30 PM, Keith Marshall <keithmarshall@xxxxxxxxxxxxxxxxxxxxx> wrote:
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).

ok I've found a way to do what I want: 
  using namespace std;
#ifdef _WIN32
#ifdef _MSC_VER // MSVC uses 64bit internally
#   define stat64 stat
#   define lstat64(x,y) stat(x,y) 
      #ifndef stat64 /* case of mingw-org .vs. mingw-w64 */
      # define stat64 _stati64
#    define lstat64(x,y) stat64(x,y)
Since I don't have VStudio to test I'll leave the MSC_VER block as is.

The example I pointed to, which segfaulted. did so because the printf for file size
used %lld when st_size came from {struct stat}.st_size; it worked when, I suppose, I 
compiled with 64-bit mingw-w64 and the macros were set up to make file size 64 bit.
(I thought 
Sorry I jumped to a conclusion that it was supposed to work.
MinGW-users mailing list

This list observes the Etiquette found at 
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:
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe