[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: file offsets used by fseek and ftell

From: John W. Eaton
Subject: Re: file offsets used by fseek and ftell
Date: Wed, 21 Jan 2004 13:51:20 -0600

On  4-Jan-2004, Schloegl Alois <address@hidden> wrote:

| Zitat von "John W. Eaton" <address@hidden>:
| > On 21-Nov-2003, JD Cole <address@hidden> wrote:
| >
| > | Could this be accomplished using a 64-bit (long long). If I'm
| > | not totally off base, that may be a better solution.
| >
| > With gcc 3.4, streamoff and streampos are classes that hold 64-bit
| > ints (either long long or int64_t).  But they are not simple typedefs
| > for either of these types, so it is still not possible to write
| > something like
| >
| >   streampos pos = ...;
| >
| >   long long ftell_retval = (long long) pos;
| >
| > because there is no way to cast a streampos or streamoff type to an
| > integer.
| >
| > For portability, we can't assume that these types are any particular
| > integer value.  Different systems are free to implement streamoff and
| > streampos (or fpos_t if you are using C) in any way they choose
| > (provided that they meet the rather limited constraints of the
| > respective standards).
| According to your suggestion in
| http://www.octave.org/mailing-lists/bug-octave/2003/474
| , I'd like to continue the discussion.
| In summary the above statement says, it is not possible to check the
| position of the file pointer like in this (illustrative) example:
| pos = ftell(fid);
| if pos == 50,
|     fprintf(1,'file pointer points to position 50\n');
| else
|     fprintf(1,'file pointer does not point to 50 but to %i\n',pos);
| end,
| This is a major change of the functionality of Octave. I.e it breaks
| at least my libraries (see http://biosig.sf.net/ in case you want to
| know more) which are based on the old FTELL.

I see now that it is possible to convert an integer to a streampos or
streamoff value, so you can do the comparison above.  I've checked in
some changes to allow this.  So you can do the following operations
with streamoff objects and integer values:

  +, -, +=, -=, ==, !=

You can also call fseek with an integer value to go to a specific
location in a file given an integer.  But you still can't extract an
integer value from a streamoff object, and if you are working with
large files, you might not be able to use an integer value to get to
every location in the file (the int might not be large enough) though
we probably won't encounter this problem for a while.

I realize that this is a change from the way Octave used to work,
and that it is not fully compatible with Matlab, but is it good


reply via email to

[Prev in Thread] Current Thread [Next in Thread]