WIN32 上 struct __stat64 和 struct _stati64 有什么区别?

发布于 2024-11-18 02:17:55 字数 1007 浏览 5 评论 0原文

我正在编写一些代码,这些代码需要在自 WIN2000 以来的每个版本的 Windows 上运行,并且还需要使用宽文件路径。

我需要调用 stat 的一些变体来获取文件长度。该文件可能大于 4GB。

以下是 MSDN Visual Studio .NET 2003[1] 文档中的相关部分:

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 
);

[1] https://web.archive.org/web/20110506201149/http://msdn.microsoft.com/en-us/library/14h5k7ff(v=VS.71).aspx

我可以弄清楚__stat64结构和_stati64结构之间的区别。我知道我想使用 _wstat64_wstati64,但 MSDN 没有说明哪个更好

有什么建议吗?

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 
);

[1] https://web.archive.org/web/20110506201149/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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑着哭最痛 2024-11-25 02:17:55

以下是 mingw wchar.h #include 文件中的 __stat64 和 _stati64 结构:

#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;
};

根据这些结构,似乎 _stat64 是比 stati64 更好的选择 因为:

  1. st_mode_mode_t 而不是 unsigned short
  2. 时间表示为_time64_t 而不是 time_t,因此它与 NTFS 文件系统可以表示的范围相同,并且不会削弱为 32 位 time_t< /代码>。

我仍然很困惑,但这似乎更接近正确答案。

另请注意,_stat64 需要 MSVCRT_VERSION > 0x0601,这意味着它更现代。

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:

  1. st_mode is _mode_t and not unsigned short
  2. Time is expressed as a _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.

吐个泡泡 2024-11-25 02:17:55

我不是 100% 确定,但看起来像:

  • stat:32 位时间戳,32 位文件大小
  • stat64 :64 位时间戳,32 位文件大小
  • < code>stati64:64 位时间戳,64 位文件大小

因此您需要 wstati64

这来自 MSDN 上的以下段落:

如果文件上的日期戳晚于 1970 年 1 月 1 日午夜且早于 2038 年 1 月 18 日 19:14:07(UTC),除非您使用 _stat64 或 < code>_wstat64,在这种情况下,日期可以表示到 UTC 时间 3000 年 12 月 31 日 23:59:59。

st_size
文件大小(以字节为单位); _stati64_wstati64

的 64 位整数

I'm not 100% sure, but it seems like:

  • stat: 32-bit timestamp, 32-bit filesize
  • stat64 : 64-bit timestamp, 32-bit filesize
  • stati64: 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 _stat64 or _wstat64, in which case the date can be represented up till 23:59:59, December 31, 3000, UTC.

and

st_size
Size of the file in bytes; a 64-bit integer for _stati64 and _wstati64

风月客 2024-11-25 02:17:55

文档说:

第一个数字后缀(3264)表示所使用的时间类型的大小; 第二个后缀是 i32i64,指示文件大小是表示为 32 位还是 64 位整数

The documentation says:

The first numerical suffix (32 or 64) indicates the size of the time type used; the second suffix is either i32 or i64, indicating whether the file size is represented as a 32-bit or 64-bit integer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文