I was advised by a friend of mine to use fread64, fwrite64 instead of fread and fwrite. Does this exist? Been looking for it's documentation but I haven't found one.

No. I think it is a Solaris-specific extension.

Do you think you will need to read or write files larger than 2GB?

Yes, I used fopen64 to open the iso image which is 4.3gb, but I used fread and fwrite.

None of this stuff is standard. You'll need to check your compiler's documentation. In some cases fread and fwrite work just fine once you've opened a file with fopen64. In other cases you'll need to use some special functions and/or variables. Sometimes the fseek and ftell functions are modified instead.

Alas, this is all I know about it (having never used it myself).

Good luck.

Thanks. But is there someway that I could edit the fread and fwrite so that it would correspond to fread64 and fwrite64.

I suppose you could, but you really have no valid reason to go dinking around with the standard library. (You'll break all kinds of stuff.)

You still haven't told us what system you are using. Have you looked it up in your system/compiler's documentation?

You are doing non-standard stuff. Even so, that stuff was written to be used a certain way. Less grief comes from doing it the recommended (i.e. documented) way. That is, use the functions given you the way they are supposed to be used.

Hope this helps.

Not exactly edit the whole fread and fwrite in the standard library. Creating an interface that would correspond to the fread64 and fwrite64 would do. I'm using g++ version 4.0+ compiler, I'm doing it in linux. I think g++ does not support it.

Yes, the GCC supports it. (It is the glibc that made it possible for most linux platforms.)

Compile with g++ -D_FILE_OFFSET_BITS=64 . See here. This changes all the file I/O to take 64-bit offsets instead of 32-bit.

Good luck.

I've already included it in my compiler options, still it gives me the error "fread64 was not declared in this scope". T_T

I would just like to clarify, I should define _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE to the .cpp files where I use fread and fwrite?

Forget the stupid fread64() and fwrite64() functions! Use fread() and fwrite(). Once you have enabled 64-bit access all the usual functions will work with 64-bit files.

Good luck.

> I should define _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE to the .cpp files where I use fread and fwrite?
yes, if you want to use files of sizes beyond the usual limit of 2GB on 32 bit systems. see the documentation for these macros http://www.delorie.com/gnu/docs/glibc/libc_13.html
if you are on linux, you also need to have these and -D_FILE_OFFSET_BITS=64 when you compile the kernel. eg.

CFLAGS += -Wall -O2 -D"LINUX" -D"_THREAD_SAFE" -D"_GNU_SOURCE"-D"_LARGE_FILES" -D"_LARGEFILE64_SOURCE" -D"_FILE_OFFSET_BITS=64"
This article has been dead for over six months. Start a new discussion instead.