【发布时间】:2015-12-03 20:12:51
【问题描述】:
使用v140_xp 作为Platform Toolset(目标 Win32)运行以下使用 Visual C++ 2015 Express 编译的 example for _stat from MSDN(目标 Win32)在 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。p>
这是一个错误还是我错过了什么?
【问题讨论】:
-
你能用绝对路径测试你的例子吗?
-
MSDN: connect.microsoft.com/VisualStudio/feedback/details/1557168/… - 听起来像是 VS2015 的错误
-
也许
_fstat()会起作用(我怀疑) -
vc140_xp似乎存在一些问题。可悲的是,我不认为他们会推动解决这个问题作为高优先级,因为 XP 已经过时了。如果出于可移植性原因,GetFileAttributesEx不是一个选项,您可能需要考虑针对旧版本而不是等待。 -
我们已经修复了这个错误,并正在努力将修复纳入更新。当我们锁定详细信息后,我们将使用更多信息解决 Connect 错误。谢谢。
标签: c++ visual-studio winapi visual-c++ visual-studio-2015