I'm working on some code that needs to run on every version of windows since WIN2000 and also needs to work with wide file paths.
I need to call some variant of stat
to get the file length. The file may be larger than 4GB.
Here's the relevant section from the MSDN Visual Studio .NET 2003[1] documentation:
int _stat( const char *path, struct _stat *buffer ); int _stat64( const char *path, struct __stat64 *buffer ); int _stati64( const char *path, struct _stati64 *buffer ); int _wstat( const wchar_t *path, struct _stat *buffer ); int _wstat64( const wchar_t *path, struct __stat64 *buffer ); int _wstati64( const wchar_t *path, struct _stati64 *buffer );
I can't figure out the difference between the __stat64
structure and the _stati64
structure. I know that I want to use _wstat64
or _wstati64
but MSDN is silent on which is better.
Any suggestions?
Here are the __stat64 and the _stati64 structures from the mingw wchar.h #include
file:
#if defined (__MSVCRT__) struct _stati64 { _dev_t st_dev; _ino_t st_ino; unsigned short st_mode; short st_nlink; short st_uid; short st_gid; _dev_t st_rdev; __int64 st_size; time_t st_atime; time_t st_mtime; time_t st_ctime; }; #if __MSVCRT_VERSION__ >= 0x0601 struct __stat64 { _dev_t st_dev; _ino_t st_ino; _mode_t st_mode; short st_nlink; short st_uid; short st_gid; _dev_t st_rdev; __int64 st_size; __time64_t st_atime; __time64_t st_mtime; __time64_t st_ctime; };
According to these structures, it seems that _stat64
is a better choice than stati64
because:
st_mode
is _mode_t
and not unsigned short
_time64_t
and not a time_t
, so it has the same range that can be expressed by the NTFS file system, and is not crippled to the 32-bit time_t
. I'm still confused, but this seems closer to the correct answer.
Notice also that the _stat64
requires MSVCRT_VERSION
> 0x0601
, which implies that it is more modern.