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

Guido van Rossum gvanrossum@users.sourceforge.net
Tue, 16 Jan 2001 12:53:33 -0800


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

Modified Files:
	fileobject.c 
Log Message:
Rationalizing the fallback code for portable fseek -- this is all much
simpler if we use fgetpos and fsetpos, rather than trying to mess with
platform-specific TELL64 alternatives.

Of course, this hasn't been tested on a 64-bit platform, so I may have
to withdraw this -- but I'm hopeful, and Trent Mick supports this
patch!


Index: fileobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.106
retrieving revision 2.107
diff -C2 -r2.106 -r2.107
*** fileobject.c	2001/01/15 10:36:56	2.106
--- fileobject.c	2001/01/16 20:53:31	2.107
***************
*** 56,68 ****
  #endif
  
- /* define the appropriate 64-bit capable tell() function */
- #if defined(MS_WIN64)
- #define TELL64 _telli64
- #elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(_HAVE_BSDI) || defined(__APPLE__)
- /* NOTE: this is only used on older
-    NetBSD prior to f*o() funcions */
- #define TELL64(fd) lseek((fd),0,SEEK_CUR)
- #endif
- 
  
  typedef struct {
--- 56,59 ----
***************
*** 258,280 ****
  	return _fseek(fp, offset, whence);
  #elif defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_FPOS_T >= 8
! 	/* lacking a 64-bit capable fseek() (as Win64 does) use a 64-bit capable
! 		fsetpos() and tell() to implement fseek()*/
  	fpos_t pos;
  	switch (whence) {
! 		case SEEK_CUR:
! 			if (fgetpos(fp, &pos) != 0)
! 				return -1;
! 			offset += pos;
! 			break;
! 		case SEEK_END:
! 			/* do a "no-op" seek first to sync the buffering so that
! 			   the low-level tell() can be used correctly */
! 			if (fseek(fp, 0, SEEK_END) != 0)
! 				return -1;
! 			if ((pos = TELL64(fileno(fp))) == -1L)
! 				return -1;
! 			offset += pos;
! 			break;
! 		/* case SEEK_SET: break; */
  	}
  	return fsetpos(fp, &offset);
--- 249,266 ----
  	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()*/
  	fpos_t pos;
  	switch (whence) {
! 	case SEEK_END:
! 		if (fseek(fp, 0, SEEK_END) != 0)
! 			return -1;
! 		/* fall through */
! 	case SEEK_CUR:
! 		if (fgetpos(fp, &pos) != 0)
! 			return -1;
! 		offset += pos;
! 		break;
! 	/* case SEEK_SET: break; */
  	}
  	return fsetpos(fp, &offset);