I need a compatible stat64

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

I need a compatible stat64

Greg Jung
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? 


#ifndef _MSC_VER
# include <libgen.h>
# include <sys/types.h>
#endif
#include <sys/fcntl.h>
#include <sys/stat.h>
#ifndef _MSC_VER
# include <unistd.h> 
#endif
...
#ifdef __CYGWIN__
#define stat64 stat
#define lstat64 lstat
// for religious reasons, CYGWIN doesn't do lstat64
#endif
...
#ifdef _WIN32
//
#ifdef _MSC_VER // MSVC uses 64bit internally
#   define stat64 stat
#   define lstat64(x,y) stat(x,y) 
#else
#    define lstat64(x,y) stat64(x,y)
#endif

...
struct stat64 statStruct;
F:/gdl/src/file.cpp:400:22: error: aggregate 'FindInDir(const DString&, const DString&)::stat64 statStruct' has incomplete type and cannot be defined
     struct stat64    statStruct;
                      ^
F:/gdl/src/file.cpp:258:37: error: invalid use of incomplete type 'struct FindInDir(const DString&, const DString&)::stat64'

I tried a simple #define stat64 __stat64 in sys/stat.h but that doesn't fly.

Thanks,
Greg

------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: I need a compatible stat64

Eli Zaretskii
> Date: Mon, 4 Jan 2016 22:02:20 -0800
> From: Greg Jung <[hidden email]>
>
> 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.

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: I need a compatible stat64

Greg Jung


On Tue, Jan 5, 2016 at 7:56 AM, Eli Zaretskii <[hidden email]> wrote:
> Date: Mon, 4 Jan 2016 22:02:20 -0800
> From: Greg Jung <[hidden email]>
>
> 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?
 
mingw 3.21, recently built from sourceforge download. 

$ gcc -v
Using built-in specs.
COLLECT_GCC=D:\mingw\mingworg\bin\gcc.exe
COLLECT_LTO_WRAPPER=d:/mingw/mingworg/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)

 
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.
 
I want to use a name that is not platform-specific.  
stat64 is available and documented ...


maybe the best way would be to #define _FILE_OFFSET_BITS 64 
and use stat - although it doesn't appear stat.h would catch that.  Also, it leaves the
type ambiguous for the programmer.

BTW, I found a segmentation fault error when compiling this example (presented with stat64 removed):

(which worked compiled with the mingw-w64 gcc 5.2)


------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: I need a compatible stat64

Eli Zaretskii
> Date: Tue, 5 Jan 2016 12:19:15 -0800
> From: Greg Jung <[hidden email]>
>
>     What version of the MinGW runtime do you have?
>
> mingw 3.21, recently built from sourceforge download.
> [...]
>     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.
>
> I want to use a name that is not platform-specific.

If there is one, yes.  But what if there isn't?

> stat64 is available and documented ...
>
> http://www.gnu.org/software/libc/manual/html_node/Reading-Attributes.html 

That manual is about glibc, whereas with MinGW you are using the
Microsoft runtime libraries (with small additions from the MinGW
project).  So what that manual says is not very relevant to your
problem.

I've just looked in the 3.21 headers, and I see no declaration of a
function named stat64 there.  I do see _stat64.  So I still think this
is what you should use with MinGW.

> BTW, I found a segmentation fault error when compiling this example (presented
> with stat64 removed):
> http://mingw-users.1079350.n2.nabble.com/MinGw-opendir-stat64-and-related-td7268987.html
>
> (which worked compiled with the mingw-w64 gcc 5.2)

MinGW-w64 is a separate project, with subtly incompatible header
files.  You cannot always copy to MinGW what you have working with
MinGW-w64.

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: I need a compatible stat64

Keith Marshall
In reply to this post by Eli Zaretskii
On 05/01/16 15:56, Eli Zaretskii wrote:

>> Date: Mon, 4 Jan 2016 22:02:20 -0800
>> From: Greg Jung <[hidden email]>
>>
>> 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

------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe

chkstat.log (10K) Download Attachment
signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: I need a compatible stat64

Keith Marshall
In reply to this post by Greg Jung
On 05/01/16 20:19, Greg Jung wrote:
> BTW, I found a segmentation fault error when compiling this example
> (presented with stat64 removed):
> http://mingw-users.1079350.n2.nabble.com/MinGw-opendir-stat64-and-related-td7268987.html

<shrug> Can't do much about this, without full details; "I found a
segmentation fault error" doesn't tell me anything useful.

> (which worked compiled with the mingw-w64 gcc 5.2)

Different project; different product, so irrelevant.

--
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F


------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe

signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: I need a compatible stat64

Greg Jung
In reply to this post by Keith Marshall


On Tue, Jan 5, 2016 at 11:30 PM, Keith Marshall <[hidden email]> wrote:
On 05/01/16 15:56, Eli Zaretskii wrote:
>> Date: Mon, 4 Jan 2016 22:02:20 -0800
>> From: Greg Jung <[hidden email]>
>>
>> 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) 
#else
      #ifndef stat64 /* case of mingw-org .vs. mingw-w64 */
      # define stat64 _stati64
      #endif
#    define lstat64(x,y) stat64(x,y)
#endif
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
[hidden email]

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:[hidden email]?subject=unsubscribe