Fopen 无法打开二进制文件
我有一个巨大的二进制文件,大小为 2148181087 字节(> 2gb),
我正在尝试执行 fopen (file, "r")
但失败了
无法打开:xyz 文件(值太 大到可以存储在数据类型中)
我在手册页上读到,当文件大小>时,会收到EOVERFLOW错误。 2GB。
奇怪的是,我使用了另一个输入文件,它也“几乎”与第一个文件 2142884400 字节(也 >2GB)一样大,fopen
可以很好地处理这个问题。
fopen
的文件大小是否有任何限制,或者是否有其他方法可以解决此问题?
I have a huge binary file which is 2148181087 bytes (> 2gb)
I am trying to do fopen (file, "r")
and it failed with
Can not open: xyz file (Value too
large to be stored in data type)
I read on the man page EOVERFLOW error is received when the file size > 2gb.
The weird thing is, I use a different input file which is also "almost" as big as the first file 2142884400 bytes (also >2gb), fopen
works fine with this.
Is there any cutoff on the file size for fopen
or is there any alternate way to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
截止值是 2GB,与您的想法相反,它不是 2,000,000,000 (2x10003)。
为 2,147,483,648 (2x10243)。因此,您的第二个有效文件实际上大小小于 2GB)。
在计算机世界中,2GB 在硬盘驱动器制造商的心目中只是 2,000,000,000,因此他们可以说他们的磁盘比实际大小更大:-) - 这让他们说他们的磁盘实际上是 2.1GB。
The cutoff is 2GB which, contrary to what you may think, is not 2,000,000,000 (2x10003).
It's 2,147,483,648 (2x10243). So your second file, which works, is actually less than 2GB in size).
2GB, in the computer world, is only 2,000,000,000 in the minds of hard drive manufacturers so they can say their disks are bigger than they really are :-) - it lets them say their disks are actually 2.1GB.
“解决此问题的替代方法”取决于您使用的操作系统/库。
对于 GNU C 库,您可以使用
fopen64
作为fopen
的替代品;它使用 64 位文件句柄(还有一个宏可以让fopen
使用 64 位文件句柄)。对于 Windows,您可能必须切换到 Win32 文件管理 API,您可以使用
CreateFile
。The "alternative way to solve this" depends on which operating system/library you are using.
For the GNU C library, you can use
fopen64
as a replacement forfopen
; it uses 64-bit file handles (there's also a macro to havefopen
use 64-bit file handles).For Windows, you'll probably have to switch to the Win32 file management API, with which you can use
CreateFile
.