gpt4 book ai didi

c++ - Visual C++ 2015 表达 : _stat not working on Windows XP

转载 作者:可可西里 更新时间:2023-11-01 18:36:47 28 4
gpt4 key购买 nike

运行以下 example for _stat from MSDN使用 v140_xp 作为 Platform Toolset(目标 Win32)使用 Visual C++ 2015 Express 编译,在 Windows 7 上正常运行,但在我测试的几台机器上的 Windows XP 上运行不正常。

// crt_stat.c
// This program uses the _stat function to
// report information about the file named crt_stat.c.

#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>

int main()
{
struct _stat buf;
int result;
char timebuf[26];
char* filename = "crt_stat.c"; // Absolute paths like "D:\\crt_stat.c" produce the same behaviour.
errno_t err;

// Get data associated with "crt_stat.c":
result = _stat( filename, &buf );

// Check if statistics are valid:
if ( result != 0 )
{
perror( "Problem getting information" );
switch ( errno )
{
case ENOENT:
printf( "File %s not found.\n", filename );
break;
case EINVAL:
printf( "Invalid parameter to _stat.\n" );
break;
default:
/* Should never be reached. */
printf( "Unexpected error in _stat.\n" );
}
}
else
{
// Output some of the statistics:
printf( "File size : %ld\n", buf.st_size );
printf( "Drive : %c:\n", buf.st_dev + 'A' );
err = ctime_s( timebuf, 26, &buf.st_mtime );
if ( err )
{
printf( "Invalid arguments to ctime_s." );
return 1;
}
printf( "Time modified : %s", timebuf );
}
}

Windows 7 输出:

File size     : 6
Drive : D:
Time modified : Tue Sep 8 10:06:57 2015

Windows XP 输出:

Problem getting information: Invalid argument
Invalid parameter to _stat.

是的,crt_stat.c 位于也是 CWD 的可执行文件目录中。

这是 Bug 还是我遗漏了什么?

最佳答案

正如评论中指出的那样,它是一个 bug在运行时。目前 (2015-09-09) 该修复程序尚未在更新中提供,但可能很快就会提供。解决方法是改用 GetFileAttributesEx

关于c++ - Visual C++ 2015 表达 : _stat not working on Windows XP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32452777/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com