Visual c++ 2015 express: _stat在Windows XP上不工作
Visual C++ 2015 express: _stat not working on Windows XP
使用Visual c++ 2015 Express使用v140_xp
作为Platform Toolset
(目标Win32)编译的MSDN中运行以下示例在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 : %ldn", 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
代替。
在Visual c++ Redistributable for Visual Studio 2015 Update 1上解决了这个bug
我通过在这里安装更新表单解决了这个问题:https://www.microsoft.com/en-us/download/details.aspx?id=49984
相关文章:
- std::async from std::async in windows xp
- 如何在Visual Studio 2017中编译Windows XP的代码
- 如何构建使用Visual Studio 2017的Windows XP的Winsock2(WS2_32.LIB)应用程序
- WinHttpSendRequest and HTTPS on Windows XP
- 功能本地静态为Windows XP生成故障代码
- SHOpenWithDialog analog for windows XP?
- 如何检查操作系统是否至少是Windows XP SP3
- 使用Visual Studio 2012针对Windows XP构建Boost 1.52库
- 使用 Build Tools 2015 (不带 Visual Studio) 面向 Windows XP
- 有任何替代SHGetKnownFolderPath的Windows XP用户令牌的方案吗
- 当Windows XP(32位,SP3)播放声音时,随机应用程序暂停半秒钟
- 函数从windows XP中的数据包中检索标头目标地址
- GetConsoleScreenBufferInfoEx equivalent for windows XP?
- 如何跟踪Windows 7是否在C ++中以编程方式进入睡眠或休眠状态,就像在Windows XP中所做的那样
- 如何从Windows XP下的程序中知道或更改Windows事件日志的大小
- 带Realtek Alc888的活动耳机插孔(Windows XP)
- 如何使用Visual Studio 2012编译Windows XP
- Visual C 2012 Express Compied Application在Windows XP上不起作用
- 在Windows上运行C 应用程序的必要条件,并从VS 2012中获取XP定位
- 在XP上使用windows文件资源管理器时,停止打开explorer.exe任务栏