积极答复者
64位系统下 fopen 用 "a+" 模式打开5GB的文件出错,错误号 22

问题
-
现在遇到一个问题,使用fopen函数打开一个大小为5GB的文件。
打开模式为:"a+"
则返回错误,错误号为22
将打开模式改为:"a"或者"ab+" 都可以打开文件。
实在不知道这是为什么。
由于需要以"a+"模式打开文本文件,所以希望能够得到帮助。
谢谢。
编译环境是Win7 x64 专业版
vs 2005 专业版。
编译方式: x64
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <sys/stat.h>
int main()
{
FILE *fp;fp=NULL;
fp =fopen("c:\\test\\5GB","a+");
if (fp == NULL)
{
printf("NULL %d \n",errno);
return 1;
}fclose(fp);
}
Langrisser
- 已编辑 Langrisser 2015年11月27日 8:36 忘了写编译方式
答案
-
你好,
我按照你的步骤在我的电脑上测试了一下,我发现我的电脑上没有问题。我没有得到22 错误。我的电脑是windows 8.1 64 bit.
VS2013.
May
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Langrisser 2015年11月30日 10:17
全部回复
-
你好,
请问你具体的错误是:
EINVAL
Invalid argument
22?
你具体的5GB是个什么类型的文件?如果你以a+打开2GB以内的文件是否有问题?用fopen64试下。
May
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
您好,
我只能看到错误号是 22
根据MSDN的说明是:
EINVAL
Invalid argument 22 错误
我的5GB的文件是用
fsutil file createnew c:\test\5Gb 5000000000
命令产生的一个大小为5GB的空文件。
我用a+打开4GB以内的文件没问题。但是超过4GB就会出错。
Windows下我没有找到fopen64这个接口,听说他是Linux的接口,不知道如何在Windows下使用它。
Langrisser
- 已编辑 Langrisser 2015年11月30日 5:57 增加了对22号错误的说明
-
你好,
我按照你的步骤在我的电脑上测试了一下,我发现我的电脑上没有问题。我没有得到22 错误。我的电脑是windows 8.1 64 bit.
VS2013.
May
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Langrisser 2015年11月30日 10:17
-
你好,
我按照你的步骤在我的电脑上测试了一下,我发现我的电脑上没有问题。我没有得到22 错误。我的电脑是windows 8.1 64 bit.
VS2013.
May
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.谢谢您的回答,应该是微软的SDK版本问题。
我做了下述测试:
编译机:
win7 x32 + vs2013
按照静态编译(MT)
测试机:
win7 x64 上
跑了一下,没有出错。
我感觉我之前用vs2005 sp2 的(MD)编译可能有问题。SDK的版本低了。
谢谢。
Langrisser