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

Guido van Rossum gvanrossum@users.sourceforge.net
Thu, 01 Mar 2001 10:26:55 -0800


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

Modified Files:
	fileobject.c 
Log Message:
Two improvements to large file support:

- In _portable_ftell(), try fgetpos() before ftello() and ftell64().
  I ran into a situation on a 64-bit capable Linux where the C
  library's ftello() and ftell64() returned negative numbers despite
  fpos_t and off_t both being 64-bit types; fgetpos() did the right
  thing.

- Define a new typedef, Py_off_t, which is either fpos_t or off_t,
  depending on which one is 64 bits.  This removes the need for a lot
  of #ifdefs later on.  (XXX Should this be moved to pyport.h?  That
  file currently seems oblivious to large fille support, so for now
  I'll leave it here where it's needed.)


Index: fileobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.108
retrieving revision 2.109
diff -C2 -r2.108 -r2.109
*** fileobject.c	2001/01/18 03:03:16	2.108
--- fileobject.c	2001/03/01 18:26:53	2.109
***************
*** 213,224 ****
  
  
! /* a portable fseek() function
!    return 0 on success, non-zero on failure (with errno set) */
! int
  #if defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_OFF_T < 8 && SIZEOF_FPOS_T >= 8
! _portable_fseek(FILE *fp, fpos_t offset, int whence)
  #else
! _portable_fseek(FILE *fp, off_t offset, int whence)
  #endif
  {
  #if defined(HAVE_FSEEKO)
--- 213,228 ----
  
  
! /* 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
+ 
+ 
+ /* a portable fseek() function
+    return 0 on success, non-zero on failure (with errno set) */
+ int
+ _portable_fseek(FILE *fp, Py_off_t offset, int whence)
  {
  #if defined(HAVE_FSEEKO)
***************
*** 254,273 ****
     Return -1 on failure with errno set appropriately, current file
     position on success */
! #if defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_OFF_T < 8 && SIZEOF_FPOS_T >= 8
! fpos_t
! #else
! off_t
! #endif
  _portable_ftell(FILE* fp)
  {
! #if defined(HAVE_FTELLO) && defined(HAVE_LARGEFILE_SUPPORT)
! 	return ftello(fp);
! #elif defined(HAVE_FTELL64) && defined(HAVE_LARGEFILE_SUPPORT)
! 	return ftell64(fp);
! #elif SIZEOF_FPOS_T >= 8 && defined(HAVE_LARGEFILE_SUPPORT)
  	fpos_t pos;
  	if (fgetpos(fp, &pos) != 0)
  		return -1;
  	return pos;
  #else
  	return ftell(fp);
--- 258,273 ----
     Return -1 on failure with errno set appropriately, current file
     position on success */
! Py_off_t
  _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);
***************
*** 281,289 ****
  	int whence;
  	int ret;
! #if defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_OFF_T < 8 && SIZEOF_FPOS_T >= 8
! 	fpos_t offset, pos;
! #else
! 	off_t offset;
! #endif /* !MS_WIN64 */
  	PyObject *offobj;
  
--- 281,285 ----
  	int whence;
  	int ret;
! 	Py_off_t offset;
  	PyObject *offobj;
  
***************
*** 322,330 ****
  {
  	int ret;
! #if defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_OFF_T < 8 && SIZEOF_FPOS_T >= 8
! 	fpos_t newsize;
! #else
! 	off_t newsize;
! #endif
  	PyObject *newsizeobj;
  
--- 318,322 ----
  {
  	int ret;
! 	Py_off_t newsize;
  	PyObject *newsizeobj;
  
***************
*** 397,405 ****
  file_tell(PyFileObject *f, PyObject *args)
  {
! #if defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_OFF_T < 8 && SIZEOF_FPOS_T >= 8
! 	fpos_t pos;
! #else
! 	off_t pos;
! #endif
  
  	if (f->f_fp == NULL)
--- 389,393 ----
  file_tell(PyFileObject *f, PyObject *args)
  {
! 	Py_off_t pos;
  
  	if (f->f_fp == NULL)