开发者

Fopen failing for binary file

开发者 https://www.devze.com 2022-12-11 20:41 出处:网络
I have a huge bin开发者_高级运维ary file which is2148181087 bytes (> 2gb) I am trying to do fopen (file, \"r\") and it failed with

I have a huge bin开发者_高级运维ary 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号