[prog] fopen and large files (RH9)
Almut Behrens
almut-behrens at gmx.net
Mon Jan 17 07:55:27 EST 2005
On Fri, Jan 14, 2005 at 06:49:16PM +0000, Conor Daly wrote:
> O_LARGEFILE
> On 32-bit systems that support the Large Files System, allow
> files whose sizes cannot be represented in 31 bits to be opened.
>
>
> I presume this is my problem. Now, doing an 'rpm -qi ca-ingres' I see the
> build host is called: hanje04-sles8.ca.com and the 'sles8' leads me to
> suspect that it was built on a Suse enterprise 8 machine. Does that support
> large filesystems? Is there a call to make I can use to get open(2) to use
> the O_LARGEFILE flag?
Hi Conor,
normally, you compile a program with LFS (large file support) by adding
two macros at the top of the source, _before_ including header files.
You can either write:
#define _LARGEFILE_SOURCE
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
int main() {
FILE *f;
f = fopen("./file", "r");
}
This transparently replaces all relevant functions and data structures
under the hood with the appropriate 64-bit versions (fopen64(), etc.).
Or, if you think that's too much magic, you can use the following pair
of macros, and then explicitly call fopen64(), and whatever other
file IO routines you need:
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#include <stdio.h>
int main() {
FILE *f;
f = fopen64("./file", "r");
}
IOW, you could simply try adding this, and recompile the sources -- and
hope it doesn't have any side effects... ;-)
Unfortunately, there are a number of pitfalls, if the original source
had not been written with LFS in mind. Feeling a bit lazy at the
moment to write it all down myself, I quickly googled and found
http://www.unet.univie.ac.at/aix/aixprggd/genprogc/prg_lrg_files.htm#AppAn169stcl
This is AIX specific, but some of the warnings hold for Linux, too, at
least the general idea behind them. Maybe you can google up a better
document yourself...
Also see "info libc 'Feature Test Macros'" for the meaning of those
(and similar) macros.
Good luck,
Almut
More information about the Programming
mailing list