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:
i开发者_开发技巧nt _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 );
[1] http://msdn.microsoft.com/en-us/library/14h5k7ff(v=VS.71).aspx
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_modeis_mode_tand notunsigned short- Time is expressed as a
_time64_tand not atime_t, so it has the same range that can be expressed by the NTFS file system, and is not crippled to the 32-bittime_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.
I'm not 100% sure, but it seems like:
stat: 32-bit timestamp, 32-bit filesizestat64: 64-bit timestamp, 32-bit filesizestati64: 64-bit timestamp, 64-bit filesize
So you would need wstati64.
This from the following paragraphs on MSDN:
The date stamp on a file can be represented if it is later than midnight, January 1, 1970, and before 19:14:07 January 18, 2038, UTC unless you use
_stat64or_wstat64, in which case the date can be represented up till 23:59:59, December 31, 3000, UTC.
and
st_sizeSize of the file in bytes; a 64-bit integer for_stati64and_wstati64
The documentation says:
The first numerical suffix (
32or64) indicates the size of the time type used; the second suffix is eitheri32ori64, indicating whether the file size is represented as a 32-bit or 64-bit integer.
加载中,请稍侯......
精彩评论