[Python-checkins] CVS: python/dist/src/Objects fileobject.c,2.119,2.120

Guido van Rossum gvanrossum@users.sourceforge.net
Wed, 05 Sep 2001 07:58:13 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv15594/Objects

Modified Files:
	fileobject.c 
Log Message:
Changes to automatically enable large file support on some systems.
I believe this works on Linux (tested both on a system with large file
support and one without it), and it may work on Solaris 2.7.

The changes are twofold:

(1) The configure script now boldly tries to set the two symbols that
    are recommended (for Solaris and Linux), and then tries a test
    script that does some simple seeking without writing.

(2) The _portable_{fseek,ftell} functions are a little more systematic
    in how they try the different large file support options: first
    try fseeko/ftello, but only if off_t is large; then try
    fseek64/ftell64; then try hacking with fgetpos/fsetpos.

I'm keeping my fingers crossed.  The meaning of the
HAVE_LARGEFILE_SUPPORT macro is not at all clear.

I'll see if I can get it to work on Windows as well.



Index: fileobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.119
retrieving revision 2.120
diff -C2 -d -r2.119 -r2.120
*** fileobject.c	2001/08/24 18:34:26	2.119
--- fileobject.c	2001/09/05 14:58:11	2.120
***************
*** 209,217 ****
  
  
! /* An 8-byte off_t-like type */
! #if defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_OFF_T < 8 && SIZEOF_FPOS_T >= 8
  typedef fpos_t Py_off_t;
  #else
! typedef off_t Py_off_t;
  #endif
  
--- 209,221 ----
  
  
! /* Our very own off_t-like type, 64-bit if possible */
! #if !defined(HAVE_LARGEFILE_SUPPORT)
! typedef off_t Py_off_t;
! #elif SIZEOF_OFF_T >= 8
! typedef off_t Py_off_t;
! #elif SIZEOF_FPOS_T >= 8
  typedef fpos_t Py_off_t;
  #else
! #error "Large file support, but neither off_t nor fpos_t is large enough."
  #endif
  
***************
*** 222,226 ****
  _portable_fseek(FILE *fp, Py_off_t offset, int whence)
  {
! #if defined(HAVE_FSEEKO)
  	return fseeko(fp, offset, whence);
  #elif defined(HAVE_FSEEK64)
--- 226,232 ----
  _portable_fseek(FILE *fp, Py_off_t offset, int whence)
  {
! #if !defined(HAVE_LARGEFILE_SUPPORT)
! 	return fseek(fp, offset, whence);
! #elif defined(HAVE_FSEEKO) && SIZEOF_OFF_T >= 8
  	return fseeko(fp, offset, whence);
  #elif defined(HAVE_FSEEK64)
***************
*** 228,232 ****
  #elif defined(__BEOS__)
  	return _fseek(fp, offset, whence);
! #elif defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_FPOS_T >= 8
  	/* lacking a 64-bit capable fseek(), use a 64-bit capable fsetpos()
  	   and fgetpos() to implement fseek()*/
--- 234,238 ----
  #elif defined(__BEOS__)
  	return _fseek(fp, offset, whence);
! #elif SIZEOF_FPOS_T >= 8
  	/* lacking a 64-bit capable fseek(), use a 64-bit capable fsetpos()
  	   and fgetpos() to implement fseek()*/
***************
*** 246,250 ****
  	return fsetpos(fp, &offset);
  #else
! 	return fseek(fp, offset, whence);
  #endif
  }
--- 252,256 ----
  	return fsetpos(fp, &offset);
  #else
! #error "Large file support, but no way to fseek."
  #endif
  }
***************
*** 257,271 ****
  _portable_ftell(FILE* fp)
  {
! #if SIZEOF_FPOS_T >= 8 && defined(HAVE_LARGEFILE_SUPPORT)
  	fpos_t pos;
  	if (fgetpos(fp, &pos) != 0)
  		return -1;
  	return pos;
- #elif defined(HAVE_FTELLO) && defined(HAVE_LARGEFILE_SUPPORT)
- 	return ftello(fp);
- #elif defined(HAVE_FTELL64) && defined(HAVE_LARGEFILE_SUPPORT)
- 	return ftell64(fp);
  #else
! 	return ftell(fp);
  #endif
  }
--- 263,279 ----
  _portable_ftell(FILE* fp)
  {
! #if !defined(HAVE_LARGEFILE_SUPPORT)
! 	return ftell(fp);
! #elif defined(HAVE_FTELLO) && SIZEOF_OFF_T >= 8
! 	return ftello(fp);
! #elif defined(HAVE_FTELL64)
! 	return ftell64(fp);
! #elif SIZEOF_FPOS_T >= 8
  	fpos_t pos;
  	if (fgetpos(fp, &pos) != 0)
  		return -1;
  	return pos;
  #else
! #error "Large file support, but no way to ftell."
  #endif
  }