From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: David Fox <dsfox@cogsci.ucsd.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] in_channel_length fails for files longer than max_int
Date: Mon, 28 May 2001 15:13:25 +0200 [thread overview]
Message-ID: <20010528151325.A21783@pauillac.inria.fr> (raw)
In-Reply-To: <luitj3swez.fsf@hci.ucsd.edu>; from dsfox@cogsci.ucsd.edu on Mon, May 14, 2001 at 09:55:00AM -0700
> The pervasive function in_channel_length fails when the file size is
> too large for an int, but it doesn't raise an exception. The code in
> io.c just checks for lseek errors. Would a check for end > max_int be
> worthwhile?
That's one possibility. The code for channel_size is already less
portable than it ought to be:
> long channel_size(struct channel *channel)
> {
> long end;
> end = lseek(channel->fd, 0, SEEK_END);
The return type of "lseek" is actually off_t, which is specified to be
"an extended signed integral type". So, there is no guarantee that a
"long" can hold a file offset without losing bits, although it happens
to work on most Unix systems. The check you suggest would handle this
case as well.
Then, the conversion of the long into an OCaml "int" loses one more
bit of precision. Since off_t is signed, we don't actually lose bits,
but may end up with a negative file size, which is tolerable for
printing, but will cause an error if it is passed to "seek".
Chris Hecker suggests:
> Shouldn't all of the file size stuff be converted to int64s now anyway?
That's another option, especially since it would allow "lseek64" or
"llseek" to be used internally instead of "lseek" when available, thus
making it possible to work with files bigger than 2Gb on a 32-bit
platform. However, we can't break backward compatibility, so we'd
have to add new functions "long_seek" and "long_{in,out}_channel_length"
to the OCaml API.
- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
prev parent reply other threads:[~2001-05-28 13:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <William Chesters's message of "Sun, 13 May 2001 23:29:24 +0200 (CEST)">
2001-05-14 16:55 ` David Fox
2001-05-13 6:24 ` Chris Hecker
2001-05-28 13:13 ` Xavier Leroy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010528151325.A21783@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=caml-list@inria.fr \
--cc=dsfox@cogsci.ucsd.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox