Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] error opening large file
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] error opening large file
> i get the following error when i open a large file (2561435180 bytes):
>    let chan = open_in( "" );;
>    Uncaught exception:
>    Sys_error
>    " Value too large for defined data type".
> is there a 2G file size limitation?  if so, why?
> i found the same bug in erlang, though C is ok with it.

Actually, this limitation is in the kernel and C library.  To ensure
backward compatibility with old programs that assume that the size of
a file fits in a 32-bit signed integer, system calls come in two
versions and/or with special options, one to select 32-bit file sizes
(and fail on files larger than 2G), one to select 64-bit file sizes.
The choice between the two versions is done through compile-time
defines, and the default can be either 32 or 64 depending on the C library.

You could try to recompile the OCaml sources with the -D_FILE_OFFSET_BITS=64
flag.  That will let you open the large file, and read it sequentially,
but of course file positions and stats (as returned by
in_channel_length, seek_in, Unix.stat, etc) will be wrong, since they
wrap around at 2^30 on a 32-bit machine.

Now that I think I've figured it out, I plan to compile future
versions of OCaml in 64-bit-file-size mode, and add new library functions
to manipulate file positions and sizes as 64-bit integers (seek_in64,
Unix.stat64, etc).

- Xavier Leroy
Bug reports:  FAQ:
To unsubscribe, mail  Archives: