[Python-checkins] CVS: python/dist/src/Python pythonrun.c,2.122,2.123
Tim Peters
tim_one@users.sourceforge.net
Sat, 17 Feb 2001 14:02:36 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv21318/python/dist/src/Python
Modified Files:
pythonrun.c
Log Message:
Bug #132850 unix line terminator on windows.
Miserable hack to replace the previous miserable hack in maybe_pyc_file.
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.122
retrieving revision 2.123
diff -C2 -r2.122 -r2.123
*** pythonrun.c 2001/02/11 04:35:39 2.122
--- pythonrun.c 2001/02/17 22:02:34 2.123
***************
*** 581,596 ****
/* Mess: In case of -x, the stream is NOT at its start now,
and ungetc() was used to push back the first newline,
! which makes the current stream position formally undefined
! until that newline is read back. So first we getc(), so
! that ftell() is well-defined.
*/
- const int maybepushedback = getc(fp);
- const long currentpos = ftell(fp);
int ispyc = 0;
! rewind(fp);
! ispyc = fread(buf, 1, 2, fp) == 2 &&
! ((unsigned int)buf[1]<<8 | buf[0]) == halfmagic;
! fseek(fp, currentpos, SEEK_SET);
! ungetc(maybepushedback, fp);
return ispyc;
}
--- 581,600 ----
/* Mess: In case of -x, the stream is NOT at its start now,
and ungetc() was used to push back the first newline,
! which makes the current stream position formally undefined,
! and a x-platform nightmare.
! Unfortunately, we have no direct way to know whether -x
! was specified. So we use a terrible hack: if the current
! stream position is not 0, we assume -x was specified, and
! give up. Bug 132850 on SourceForge spells out the
! hopelessness of trying anything else (fseek and ftell
! don't work predictably x-platform for text-mode files).
*/
int ispyc = 0;
! if (ftell(fp) == 0) {
! if (fread(buf, 1, 2, fp) == 2 &&
! ((unsigned int)buf[1]<<8 | buf[0]) == halfmagic)
! ispyc = 1;
! rewind(fp);
! }
return ispyc;
}