Fopen 无法打开二进制文件

发布于 2024-08-11 14:27:51 字数 374 浏览 2 评论 0原文

我有一个巨大的二进制文件,大小为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尐籹人 2024-08-18 14:27:51

截止值是 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.

债姬 2024-08-18 14:27:51

“解决此问题的替代方法”取决于您使用的操作系统/库。

对于 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 for fopen; it uses 64-bit file handles (there's also a macro to have fopen 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文