[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: |
Fri, 23 Jan 2004 12:31:28 -0600 |
On 23-Jan-2004, John W. Eaton <address@hidden> wrote:
| On 23-Jan-2004, Alois Schloegl <address@hidden> wrote:
|
| | The origin for introducing the STREAMPOS object was the ability to
| | access files larger than 4GBytes. If the issue becomes a question
| | whether octave should support, (1) access to files larger than 4GB or
| | (2) FTELL returning a numeric value, I second the later.
|
| If you (or someone) can show me a *portable* way to get the file
| position as an integer, then we can convert it back. The motivation
| for the change is to be able to support large files *and* allow Octave
| to compile with future C++ systems that don't necessarily have
| streampos/streamoff as a simple integer.
Here is a portable fix for the problem. Unfortunately, there is only
== or != for comparison, so I don't see how to use a better search
method. Obviously this is a bit of a kluge, but it is portable.
jwe
Index: src/file-io.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/file-io.cc,v
retrieving revision 1.149
diff -u -r1.149 file-io.cc
--- src/file-io.cc 22 Jan 2004 22:10:28 -0000 1.149
+++ src/file-io.cc 23 Jan 2004 18:27:38 -0000
@@ -638,7 +638,7 @@
from the beginning of the file @var{fid}.\n\
@end deftypefn")
{
- octave_value retval = streamoff_array (dim_vector (1, 1), -1);
+ octave_value retval = -1;
int nargin = args.length ();
@@ -647,7 +647,27 @@
octave_stream os = octave_stream_list::lookup (args(0), "ftell");
if (! error_state)
- retval = streamoff_array (dim_vector (1, 1), os.tell ());
+ {
+ std::streamoff tell_pos = os.tell ();
+
+ if (! error_state)
+ {
+ std::streamoff show_pos (-1);
+
+ long position = -1;
+
+ while (position < LONG_MAX)
+ {
+ if (show_pos == tell_pos)
+ break;
+
+ show_pos++;
+ position++;
+ }
+
+ retval = position;
+ }
+ }
}
else
print_usage ("ftell");