This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project. See the libstdc++ home page for more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] simplification of off64, fpos64, etc.



Perhaps because I have glibc2.1 installed, I'm getting compilation
errors that others may not have seen.  In the process of tracking them
down, I created the enclosed patch to simplify the definition and use
of the position and offset typedefs.

I wonder if the names "_IO_seek_fpos_t" and "_IO_seek_off_t" are the
best.  But I think the patch itself is worthwhile anyway.


Index: libio/libioP.h
===================================================================
RCS file: /cvs/libstdc++/libstdc++/libio/libioP.h,v
retrieving revision 1.1
diff -c -2 -r1.1 libioP.h
*** libioP.h	1999/01/22 17:14:16	1.1
--- libioP.h	1999/03/21 05:32:00
***************
*** 48,51 ****
--- 48,59 ----
  #define _IO_seek_end 2
  
+ #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
+ typedef _IO_fpos64_t _IO_seek_fpos_t;
+ typedef _IO_off64_t  _IO_seek_off_t;
+ #else
+ typedef _IO_fpos_t _IO_seek_fpos_t;
+ typedef _IO_off_t  _IO_seek_off_t;
+ #endif
+ 
  /* THE JUMPTABLE FUNCTIONS.
  
***************
*** 139,149 ****
     It matches the streambuf::seekoff virtual function.
     It is also used for the ANSI fseek function. */
! #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! typedef _IO_fpos64_t (*_IO_seekoff_t) __PMT ((_IO_FILE *FP, _IO_off64_t OFF,
! 					  int DIR, int MODE));
! #else
! typedef _IO_fpos_t (*_IO_seekoff_t) __PMT ((_IO_FILE *FP, _IO_off_t OFF,
! 					  int DIR, int MODE));
! #endif
  #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
  
--- 147,153 ----
     It matches the streambuf::seekoff virtual function.
     It is also used for the ANSI fseek function. */
! typedef _IO_seek_fpos_t (*_IO_seekoff_t) __PMT ((_IO_FILE *FP,
! 						 _IO_seek_off_t OFF,
! 						 int DIR, int MODE));
  #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
  
***************
*** 153,161 ****
     It is also used for the ANSI fgetpos and fsetpos functions.  */
  /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
! #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! typedef _IO_fpos64_t (*_IO_seekpos_t) __PMT ((_IO_FILE *, _IO_fpos64_t, int));
! #else
! typedef _IO_fpos_t (*_IO_seekpos_t) __PMT ((_IO_FILE *, _IO_fpos_t, int));
! #endif
  #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
  
--- 157,162 ----
     It is also used for the ANSI fgetpos and fsetpos functions.  */
  /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
! typedef _IO_seek_fpos_t (*_IO_seekpos_t) __PMT ((_IO_FILE *,
! 						 _IO_seek_fpos_t, int));
  #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
  
***************
*** 206,214 ****
     It matches the streambuf::sys_seek virtual function, which is
     specific to this implementation. */
! #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! typedef _IO_fpos64_t (*_IO_seek_t) __PMT ((_IO_FILE *, _IO_off64_t, int));
! #else
! typedef _IO_fpos_t (*_IO_seek_t) __PMT ((_IO_FILE *, _IO_off_t, int));
! #endif
  #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
  
--- 207,212 ----
     It matches the streambuf::sys_seek virtual function, which is
     specific to this implementation. */
! typedef _IO_seek_fpos_t (*_IO_seek_t) __PMT ((_IO_FILE *,
! 					      _IO_seek_off_t, int));
  #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
  
***************
*** 291,301 ****
  /* Generic functions */
  
! #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! extern _IO_fpos64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
! extern _IO_fpos64_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos64_t, int));
! #else
! extern _IO_fpos_t _IO_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
! extern _IO_fpos_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos_t, int));
! #endif
  
  extern void _IO_switch_to_main_get_area __P ((_IO_FILE *));
--- 289,296 ----
  /* Generic functions */
  
! extern _IO_seek_fpos_t _IO_seekoff __P ((_IO_FILE *,
! 					 _IO_seek_off_t, int, int));
! extern _IO_seek_fpos_t _IO_seekpos __P ((_IO_FILE *,
! 					 _IO_seek_fpos_t, int));
  
  extern void _IO_switch_to_main_get_area __P ((_IO_FILE *));
***************
*** 333,354 ****
  					   _IO_size_t));
  extern _IO_size_t _IO_default_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
! #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! extern _IO_fpos64_t _IO_default_seekoff __P ((_IO_FILE *,
! 					      _IO_off64_t, int, int));
! extern _IO_fpos64_t _IO_default_seekpos __P ((_IO_FILE *,
! 					      _IO_fpos64_t, int));
! #else
! extern _IO_fpos_t _IO_default_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
! extern _IO_fpos_t _IO_default_seekpos __P ((_IO_FILE *, _IO_fpos_t, int));
! #endif
  extern _IO_ssize_t _IO_default_write __P ((_IO_FILE *, const void *,
  					   _IO_ssize_t));
  extern _IO_ssize_t _IO_default_read __P ((_IO_FILE *, void *, _IO_ssize_t));
  extern int _IO_default_stat __P ((_IO_FILE *, void *));
! #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! extern _IO_fpos64_t _IO_default_seek __P ((_IO_FILE *, _IO_off64_t, int));
! #else
! extern _IO_fpos_t _IO_default_seek __P ((_IO_FILE *, _IO_off_t, int));
! #endif
  extern int _IO_default_sync __P ((_IO_FILE *));
  #define _IO_default_close ((_IO_close_t) _IO_default_sync)
--- 328,341 ----
  					   _IO_size_t));
  extern _IO_size_t _IO_default_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
! extern _IO_seek_fpos_t _IO_default_seekoff __P ((_IO_FILE *,
! 						 _IO_seek_off_t, int, int));
! extern _IO_seek_fpos_t _IO_default_seekpos __P ((_IO_FILE *,
! 						 _IO_seek_fpos_t, int));
  extern _IO_ssize_t _IO_default_write __P ((_IO_FILE *, const void *,
  					   _IO_ssize_t));
  extern _IO_ssize_t _IO_default_read __P ((_IO_FILE *, void *, _IO_ssize_t));
  extern int _IO_default_stat __P ((_IO_FILE *, void *));
! extern _IO_seek_fpos_t _IO_default_seek __P ((_IO_FILE *,
! 					      _IO_seek_off_t, int));
  extern int _IO_default_sync __P ((_IO_FILE *));
  #define _IO_default_close ((_IO_close_t) _IO_default_sync)
***************
*** 382,392 ****
  extern int _IO_file_doallocate __P ((_IO_FILE *));
  extern _IO_FILE* _IO_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
! #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! extern _IO_fpos64_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
! extern _IO_fpos64_t _IO_file_seek __P ((_IO_FILE *, _IO_off64_t, int));
! #else
! extern _IO_fpos_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
! extern _IO_fpos_t _IO_file_seek __P ((_IO_FILE *, _IO_off_t, int));
! #endif
  extern _IO_size_t _IO_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
  extern int _IO_file_stat __P ((_IO_FILE *, void *));
--- 369,376 ----
  extern int _IO_file_doallocate __P ((_IO_FILE *));
  extern _IO_FILE* _IO_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
! extern _IO_seek_fpos_t _IO_file_seekoff __P ((_IO_FILE *,
! 					      _IO_seek_off_t, int, int));
! extern _IO_seek_fpos_t _IO_file_seek __P ((_IO_FILE *,
! 					   _IO_seek_off_t, int));
  extern _IO_size_t _IO_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
  extern int _IO_file_stat __P ((_IO_FILE *, void *));
***************
*** 399,403 ****
  extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int,
  				     int, int));
! #if _G_IO_IO_FILE_VERSION == 0x20001
  extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *,
  				      int));
--- 383,387 ----
  extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int,
  				     int, int));
! #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
  extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *,
  				      int));
***************
*** 420,428 ****
  extern int _IO_str_overflow __P ((_IO_FILE *, int));
  extern int _IO_str_pbackfail __P ((_IO_FILE *, int));
! #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! extern _IO_fpos64_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
! #else
! extern _IO_fpos_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
! #endif
  extern void _IO_str_finish __P ((_IO_FILE *, int));
  
--- 404,409 ----
  extern int _IO_str_overflow __P ((_IO_FILE *, int));
  extern int _IO_str_pbackfail __P ((_IO_FILE *, int));
! extern _IO_seek_fpos_t _IO_str_seekoff __P ((_IO_FILE *,
! 					     _IO_seek_off_t, int, int));
  extern void _IO_str_finish __P ((_IO_FILE *, int));
  
***************
*** 540,556 ****
  /* _IO_pos_BAD is an _IO_fpos_t value indicating error, unknown, or EOF. */
  #ifndef _IO_pos_BAD
! # if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! #  define _IO_pos_BAD ((_IO_fpos64_t) -1)
! # else
! #  define _IO_pos_BAD ((_IO_fpos_t) -1)
! # endif
  #endif
  /* _IO_pos_as_off converts an _IO_fpos_t value to an _IO_off_t value. */
  #ifndef _IO_pos_as_off
! # if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! #  define _IO_pos_as_off(__pos) ((_IO_off64_t) (__pos))
! # else
! #  define _IO_pos_as_off(__pos) ((_IO_off_t) (__pos))
! # endif
  #endif
  /* _IO_pos_adjust adjust an _IO_fpos_t by some number of bytes. */
--- 521,529 ----
  /* _IO_pos_BAD is an _IO_fpos_t value indicating error, unknown, or EOF. */
  #ifndef _IO_pos_BAD
! # define _IO_pos_BAD ((_IO_seek_fpos_t) -1)
  #endif
  /* _IO_pos_as_off converts an _IO_fpos_t value to an _IO_off_t value. */
  #ifndef _IO_pos_as_off
! # define _IO_pos_as_off(__pos) ((_IO_seek_off_t) (__pos))
  #endif
  /* _IO_pos_adjust adjust an _IO_fpos_t by some number of bytes. */
***************
*** 560,568 ****
  /* _IO_pos_0 is an _IO_fpos_t value indicating beginning of file. */
  #ifndef _IO_pos_0
! # if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! #  define _IO_pos_0 ((_IO_fpos64_t) 0)
! # else
! #  define _IO_pos_0 ((_IO_fpos_t) 0)
! # endif
  #endif
  
--- 533,537 ----
  /* _IO_pos_0 is an _IO_fpos_t value indicating beginning of file. */
  #ifndef _IO_pos_0
! # define _IO_pos_0 ((_IO_seek_fpos_t) 0)
  #endif
  
Index: libio/fileops.c
===================================================================
RCS file: /cvs/libstdc++/libstdc++/libio/fileops.c,v
retrieving revision 1.1
diff -c -2 -r1.1 fileops.c
*** fileops.c	1999/01/22 17:14:14	1.1
--- fileops.c	1999/03/21 05:31:59
***************
*** 160,171 ****
  
  _IO_FILE *
! _IO_file_fopen (fp, filename, mode)
       _IO_FILE *fp;
       const char *filename;
       const char *mode;
  {
    int oflags = 0, omode;
    int read_write, fdesc;
    int oprot = 0666;
    if (_IO_file_is_open (fp))
      return 0;
--- 160,181 ----
  
  _IO_FILE *
! _IO_file_fopen (fp, filename, mode
! #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
! 		, oprot
! #endif
! 		)
       _IO_FILE *fp;
       const char *filename;
       const char *mode;
+ #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
+      int oprot;
+ #endif
  {
    int oflags = 0, omode;
    int read_write, fdesc;
+ #if !(defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001)
    int oprot = 0666;
+ #endif
+ 
    if (_IO_file_is_open (fp))
      return 0;
***************
*** 423,435 ****
  }
  
! _IO_pos_t
  _IO_file_seekoff (fp, offset, dir, mode)
       _IO_FILE *fp;
!      _IO_off_t offset;
       int dir;
       int mode;
  {
!   _IO_pos_t result;
!   _IO_off_t delta, new_offset;
    long count;
    /* POSIX.1 8.2.3.7 says that after a call the fflush() the file
--- 433,445 ----
  }
  
! _IO_seek_fpos_t
  _IO_file_seekoff (fp, offset, dir, mode)
       _IO_FILE *fp;
!      _IO_seek_off_t offset;
       int dir;
       int mode;
  {
!   _IO_seek_fpos_t result;
!   _IO_seek_off_t delta, new_offset;
    long count;
    /* POSIX.1 8.2.3.7 says that after a call the fflush() the file
***************
*** 591,598 ****
  }
  
! _IO_pos_t
  _IO_file_seek (fp, offset, dir)
       _IO_FILE *fp;
!      _IO_off_t offset;
       int dir;
  {
--- 601,608 ----
  }
  
! _IO_seek_fpos_t
  _IO_file_seek (fp, offset, dir)
       _IO_FILE *fp;
!      _IO_seek_off_t offset;
       int dir;
  {
Index: libio/genops.c
===================================================================
RCS file: /cvs/libstdc++/libstdc++/libio/genops.c,v
retrieving revision 1.1
diff -c -2 -r1.1 genops.c
*** genops.c	1999/01/22 17:14:15	1.1
--- genops.c	1999/03/21 05:31:59
***************
*** 468,475 ****
  }
  
! _IO_pos_t
  _IO_default_seekpos (fp, pos, mode)
       _IO_FILE *fp;
!      _IO_pos_t pos;
       int mode;
  {
--- 468,475 ----
  }
  
! _IO_seek_fpos_t
  _IO_default_seekpos (fp, pos, mode)
       _IO_FILE *fp;
!      _IO_seek_fpos_t pos;
       int mode;
  {
***************
*** 552,559 ****
  }
  
! _IO_pos_t
  _IO_default_seekoff (fp, offset, dir, mode)
       _IO_FILE *fp;
!      _IO_off_t offset;
       int dir;
       int mode;
--- 552,559 ----
  }
  
! _IO_seek_fpos_t
  _IO_default_seekoff (fp, offset, dir, mode)
       _IO_FILE *fp;
!      _IO_seek_off_t offset;
       int dir;
       int mode;
***************
*** 883,890 ****
  }
  
! _IO_pos_t
  _IO_default_seek (fp, offset, dir)
       _IO_FILE *fp;
!      _IO_off_t offset;
       int dir;
  {
--- 883,890 ----
  }
  
! _IO_seek_fpos_t
  _IO_default_seek (fp, offset, dir)
       _IO_FILE *fp;
!      _IO_seek_off_t offset;
       int dir;
  {
Index: libio/ioseekoff.c
===================================================================
RCS file: /cvs/libstdc++/libstdc++/libio/ioseekoff.c,v
retrieving revision 1.1
diff -c -2 -r1.1 ioseekoff.c
*** ioseekoff.c	1999/01/22 17:14:15	1.1
--- ioseekoff.c	1999/03/21 05:31:59
***************
*** 26,37 ****
  #include <libioP.h>
  
! _IO_pos_t
  _IO_seekoff (fp, offset, dir, mode)
       _IO_FILE *fp;
!      _IO_off_t offset;
       int dir;
       int mode;
  {
!   _IO_pos_t retval;
  
    /* If we have a backup buffer, get rid of it, since the __seekoff
--- 26,37 ----
  #include <libioP.h>
  
! _IO_seek_fpos_t
  _IO_seekoff (fp, offset, dir, mode)
       _IO_FILE *fp;
!      _IO_seek_off_t offset;
       int dir;
       int mode;
  {
!   _IO_seek_fpos_t retval;
  
    /* If we have a backup buffer, get rid of it, since the __seekoff
Index: libio/ioseekpos.c
===================================================================
RCS file: /cvs/libstdc++/libstdc++/libio/ioseekpos.c,v
retrieving revision 1.1
diff -c -2 -r1.1 ioseekpos.c
*** ioseekpos.c	1999/01/22 17:14:16	1.1
--- ioseekpos.c	1999/03/21 05:31:59
***************
*** 26,36 ****
  #include <libioP.h>
  
! _IO_pos_t
  _IO_seekpos (fp, pos, mode)
       _IO_FILE *fp;
!      _IO_pos_t pos;
       int mode;
  {
!   _IO_pos_t retval;
  
    /* If we have a backup buffer, get rid of it, since the __seekoff
--- 26,36 ----
  #include <libioP.h>
  
! _IO_seek_fpos_t
  _IO_seekpos (fp, pos, mode)
       _IO_FILE *fp;
!      _IO_seek_fpos_t pos;
       int mode;
  {
!   _IO_seek_fpos_t retval;
  
    /* If we have a backup buffer, get rid of it, since the __seekoff
Index: libio/strops.c
===================================================================
RCS file: /cvs/libstdc++/libstdc++/libio/strops.c,v
retrieving revision 1.1
diff -c -2 -r1.1 strops.c
*** strops.c	1999/01/22 17:14:17	1.1
--- strops.c	1999/03/21 05:32:00
***************
*** 206,218 ****
  }
  
! _IO_pos_t
  _IO_str_seekoff (fp, offset, dir, mode)
       _IO_FILE *fp;
!      _IO_off_t offset;
       int dir;
       int mode;
  {
    _IO_ssize_t cur_size = _IO_str_count (fp);
!   _IO_pos_t new_pos = EOF;
  
    /* Move the get pointer, if requested. */
--- 206,218 ----
  }
  
! _IO_seek_fpos_t
  _IO_str_seekoff (fp, offset, dir, mode)
       _IO_FILE *fp;
!      _IO_seek_off_t offset;
       int dir;
       int mode;
  {
    _IO_ssize_t cur_size = _IO_str_count (fp);
!   _IO_seek_fpos_t new_pos = EOF;
  
    /* Move the get pointer, if requested. */

-- 
Chip Salzenberg      - a.k.a. -      <chip@perlsupport.com>
      "When do you work?"   "Whenever I'm not busy."