changeset 16011:8122286c69a9

initial large file support for 32-bit systems * bootstrap.conf (gnulib_modules): Explicitly list largefile. * c-file-ptr-stream.cc, c-file-ptr-stream.h, oct-fstrm.cc, oct-fstrm.h, oct-iostrm.cc, oct-iostrm.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, file-io.cc: Use off_t instead of long for seek and tell file position values.
author John W. Eaton <jwe@octave.org>
date Thu, 07 Feb 2013 11:58:46 -0500
parents c5d548e4101f
children ca37c6023a79
files bootstrap.conf libinterp/interp-core/c-file-ptr-stream.cc libinterp/interp-core/c-file-ptr-stream.h libinterp/interp-core/oct-fstrm.cc libinterp/interp-core/oct-fstrm.h libinterp/interp-core/oct-iostrm.cc libinterp/interp-core/oct-iostrm.h libinterp/interp-core/oct-stdstrm.h libinterp/interp-core/oct-stream.cc libinterp/interp-core/oct-stream.h libinterp/interp-core/oct-strstrm.cc libinterp/interp-core/oct-strstrm.h libinterp/interpfcn/file-io.cc
diffstat 13 files changed, 56 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/bootstrap.conf	Thu Feb 07 11:58:40 2013 -0500
+++ b/bootstrap.conf	Thu Feb 07 11:58:46 2013 -0500
@@ -44,6 +44,7 @@
   gettimeofday
   glob
   isatty
+  largefile
   link
   lstat
   malloc-gnu
--- a/libinterp/interp-core/c-file-ptr-stream.cc	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/c-file-ptr-stream.cc	Thu Feb 07 11:58:46 2013 -0500
@@ -193,15 +193,15 @@
 }
 
 int
-c_file_ptr_buf::seek (long offset, int origin)
+c_file_ptr_buf::seek (off_t offset, int origin)
 {
-  return f ? gnulib::fseek (f, offset, origin) : -1;
+  return f ? gnulib::fseeko (f, offset, origin) : -1;
 }
 
-long
+off_t
 c_file_ptr_buf::tell (void)
 {
-  return f ? gnulib::ftell (f) : -1;
+  return f ? gnulib::ftello (f) : -1;
 }
 
 int
--- a/libinterp/interp-core/c-file-ptr-stream.h	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/c-file-ptr-stream.h	Thu Feb 07 11:58:46 2013 -0500
@@ -74,9 +74,9 @@
 
   int file_number () const { return f ? fileno (f) : -1; }
 
-  int seek (long offset, int origin);
+  int seek (off_t offset, int origin);
 
-  long tell (void);
+  off_t tell (void);
 
   void clear (void) { if (f) clearerr (f); }
 
@@ -117,10 +117,10 @@
 
   void stream_close (void) { if (buf) buf->buf_close (); }
 
-  int seek (long offset, int origin)
+  int seek (off_t offset, int origin)
     { return buf ? buf->seek (offset, origin) : -1; }
 
-  long tell (void) { return buf ? buf->tell () : -1; }
+  off_t tell (void) { return buf ? buf->tell () : -1; }
 
   void clear (void) { if (buf) buf->clear (); STREAM_T::clear (); }
 
@@ -192,10 +192,10 @@
 
   int file_number () const { return -1; }
 
-  int seek (long offset, int origin)
-    { return f ? gzseek (f, offset, origin) : -1; }
+  int seek (off_t offset, int origin)
+    { return f ? gzseek (f, offset, origin) >= 0 : -1; }
 
-  long tell (void) { return f ? gztell (f) : -1; }
+  off_t tell (void) { return f ? gztell (f) : -1; }
 
   void clear (void) { if (f) gzclearerr (f); }
 
--- a/libinterp/interp-core/oct-fstrm.cc	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/oct-fstrm.cc	Thu Feb 07 11:58:46 2013 -0500
@@ -62,7 +62,7 @@
 // Position a stream at OFFSET relative to ORIGIN.
 
 int
-octave_fstream::seek (long, int)
+octave_fstream::seek (off_t, int)
 {
   error ("fseek: invalid_operation");
   return -1;
@@ -70,7 +70,7 @@
 
 // Return current stream position.
 
-long
+off_t
 octave_fstream::tell (void)
 {
   error ("ftell: invalid_operation");
--- a/libinterp/interp-core/oct-fstrm.h	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/oct-fstrm.h	Thu Feb 07 11:58:46 2013 -0500
@@ -46,11 +46,11 @@
 
   // Position a stream at OFFSET relative to ORIGIN.
 
-  int seek (long offset, int origin);
+  int seek (off_t offset, int origin);
 
   // Return current stream position.
 
-  long tell (void);
+  off_t tell (void);
 
   // Return non-zero if EOF has been reached on this stream.
 
--- a/libinterp/interp-core/oct-iostrm.cc	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/oct-iostrm.cc	Thu Feb 07 11:58:46 2013 -0500
@@ -30,7 +30,7 @@
 // Position a stream at OFFSET relative to ORIGIN.
 
 int
-octave_base_iostream::seek (long, int)
+octave_base_iostream::seek (off_t, int)
 {
   invalid_operation ();
   return -1;
@@ -38,7 +38,7 @@
 
 // Return current stream position.
 
-long
+off_t
 octave_base_iostream::tell (void)
 {
   invalid_operation ();
--- a/libinterp/interp-core/oct-iostrm.h	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/oct-iostrm.h	Thu Feb 07 11:58:46 2013 -0500
@@ -40,11 +40,11 @@
 
   // Position a stream at OFFSET relative to ORIGIN.
 
-  int seek (long offset, int origin);
+  int seek (off_t offset, int origin);
 
   // Return current stream position.
 
-  long tell (void);
+  off_t tell (void);
 
   // Return non-zero if EOF has been reached on this stream.
 
--- a/libinterp/interp-core/oct-stdstrm.h	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/oct-stdstrm.h	Thu Feb 07 11:58:46 2013 -0500
@@ -43,12 +43,12 @@
 
   // Position a stream at OFFSET relative to ORIGIN.
 
-  int seek (long offset, int origin)
+  int seek (off_t offset, int origin)
     { return s ? s->seek (offset, origin) : -1; }
 
   // Return current stream position.
 
-  long tell (void) { return s ? s->tell () : -1; }
+  off_t tell (void) { return s ? s->tell () : -1; }
 
   // Return non-zero if EOF has been reached on this stream.
 
--- a/libinterp/interp-core/oct-stream.cc	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/oct-stream.cc	Thu Feb 07 11:58:46 2013 -0500
@@ -1028,10 +1028,10 @@
   return do_gets (max_len, err, false, who);
 }
 
-long
-octave_base_stream::skipl (long num, bool& err, const std::string& who)
+off_t
+octave_base_stream::skipl (off_t num, bool& err, const std::string& who)
 {
-  long cnt = -1;
+  off_t cnt = -1;
 
   if ((interactive || forced_interactive) && file_number () == 0)
     {
@@ -2816,10 +2816,10 @@
   return retval;
 }
 
-long
-octave_stream::skipl (long count, bool& err, const std::string& who)
+off_t
+octave_stream::skipl (off_t count, bool& err, const std::string& who)
 {
-  long retval = -1;
+  off_t retval = -1;
 
   if (stream_ok ())
     retval = rep->skipl (count, err, who);
@@ -2827,10 +2827,10 @@
   return retval;
 }
 
-long
+off_t
 octave_stream::skipl (const octave_value& tc_count, bool& err, const std::string& who)
 {
-  long retval = -1;
+  off_t retval = -1;
 
   err = false;
 
@@ -2861,7 +2861,7 @@
 }
 
 int
-octave_stream::seek (long offset, int origin)
+octave_stream::seek (off_t offset, int origin)
 {
   int status = -1;
 
@@ -2871,7 +2871,7 @@
 
       // Find current position so we can return to it if needed.
 
-      long orig_pos = rep->tell ();
+      off_t orig_pos = rep->tell ();
 
       // Move to end of file.  If successful, find the offset of the end.
 
@@ -2879,7 +2879,7 @@
 
       if (status == 0)
         {
-          long eof_pos = rep->tell ();
+          off_t eof_pos = rep->tell ();
 
           if (origin == SEEK_CUR)
             {
@@ -2899,7 +2899,7 @@
             {
               // Where are we after moving to desired position?
 
-              long desired_pos = rep->tell ();
+              off_t desired_pos = rep->tell ();
 
               // I don't think save_pos can be less than zero, but we'll
               // check anyway...
@@ -2935,7 +2935,10 @@
 {
   int retval = -1;
 
-  long xoffset = tc_offset.long_value (true);
+  // FIXME -- should we have octave_value methods that handle off_t
+  // explicitly?
+  octave_int64 val = tc_offset.int64_scalar_value ();
+  off_t xoffset = val.value ();
 
   if (! error_state)
     {
@@ -2989,10 +2992,10 @@
   return retval;
 }
 
-long
+off_t
 octave_stream::tell (void)
 {
-  long retval = -1;
+  off_t retval = -1;
 
   if (stream_ok ())
     retval = rep->tell ();
@@ -3561,17 +3564,17 @@
               // Seek to skip when inside bounds of existing file.
               // Otherwise, write NUL to skip.
 
-              long orig_pos = tell ();
+              off_t orig_pos = tell ();
 
               seek (0, SEEK_END);
 
-              long eof_pos = tell ();
+              off_t eof_pos = tell ();
 
               // Is it possible for this to fail to return us to the
               // original position?
               seek (orig_pos, SEEK_SET);
 
-              long remaining = eof_pos - orig_pos;
+              off_t remaining = eof_pos - orig_pos;
 
               if (remaining < skip)
                 {
--- a/libinterp/interp-core/oct-stream.h	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/oct-stream.h	Thu Feb 07 11:58:46 2013 -0500
@@ -345,11 +345,11 @@
 
   // Position a stream at OFFSET relative to ORIGIN.
 
-  virtual int seek (long offset, int origin) = 0;
+  virtual int seek (off_t offset, int origin) = 0;
 
   // Return current stream position.
 
-  virtual long tell (void) = 0;
+  virtual off_t tell (void) = 0;
 
   // Return TRUE if EOF has been reached on this stream.
 
@@ -460,7 +460,7 @@
 
   std::string getl (octave_idx_type max_len, bool& err, const std::string& who /* = "getl" */);
   std::string gets (octave_idx_type max_len, bool& err, const std::string& who /* = "gets" */);
-  long skipl (long count, bool& err, const std::string& who /* = "skipl" */);
+  off_t skipl (off_t count, bool& err, const std::string& who /* = "skipl" */);
 
   octave_value do_scanf (scanf_format_list& fmt_list, octave_idx_type nr, octave_idx_type nc,
                          bool one_elt_size_spec, octave_idx_type& count,
@@ -524,13 +524,13 @@
   std::string gets (const octave_value& max_len, bool& err,
                     const std::string& who /* = "gets" */);
 
-  long skipl (long count, bool& err, const std::string& who /* = "skipl" */);
-  long skipl (const octave_value& count, bool& err, const std::string& who /* = "skipl" */);
+  off_t skipl (off_t count, bool& err, const std::string& who /* = "skipl" */);
+  off_t skipl (const octave_value& count, bool& err, const std::string& who /* = "skipl" */);
 
-  int seek (long offset, int origin);
+  int seek (off_t offset, int origin);
   int seek (const octave_value& offset, const octave_value& origin);
 
-  long tell (void);
+  off_t tell (void);
 
   int rewind (void);
 
--- a/libinterp/interp-core/oct-strstrm.cc	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/oct-strstrm.cc	Thu Feb 07 11:58:46 2013 -0500
@@ -29,7 +29,7 @@
 // Position a stream at OFFSET relative to ORIGIN.
 
 int
-octave_base_strstream::seek (long, int)
+octave_base_strstream::seek (off_t, int)
 {
   error ("fseek: invalid operation");
   return -1;
@@ -37,7 +37,7 @@
 
 // Return current stream position.
 
-long
+off_t
 octave_base_strstream::tell (void)
 {
   error ("ftell: invalid operation");
--- a/libinterp/interp-core/oct-strstrm.h	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interp-core/oct-strstrm.h	Thu Feb 07 11:58:46 2013 -0500
@@ -40,11 +40,11 @@
 
   // Position a stream at OFFSET relative to ORIGIN.
 
-  int seek (long, int);
+  int seek (off_t, int);
 
   // Return current stream position.
 
-  virtual long tell (void);
+  virtual off_t tell (void);
 
   // The name of the file.
 
@@ -104,7 +104,7 @@
 
   std::ostream *output_stream (void) { return 0; }
 
-  long tell (void) { return is.tellg (); }
+  off_t tell (void) { return is.tellg (); }
 
   std::streambuf *rdbuf (void) { return is ? is.rdbuf () : 0; }
 
--- a/libinterp/interpfcn/file-io.cc	Thu Feb 07 11:58:40 2013 -0500
+++ b/libinterp/interpfcn/file-io.cc	Thu Feb 07 11:58:46 2013 -0500
@@ -436,7 +436,7 @@
 
           bool err = false;
 
-          long tmp = os.skipl (count_arg, err, who);
+          off_t tmp = os.skipl (count_arg, err, who);
 
           if (! (error_state || err))
             retval = tmp;