summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-02-17 22:02:34 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-02-17 22:02:34 (GMT)
commit6f5a4efc0afaaf87eb1f4b8be0fffd0566352c8d (patch)
tree5797085fb366bbec627d64d1bf82dec401e7de10 /Python/pythonrun.c
parent657ba27ddecd7393e6a93e5c7249573ed0174d72 (diff)
downloadcpython-6f5a4efc0afaaf87eb1f4b8be0fffd0566352c8d.zip
cpython-6f5a4efc0afaaf87eb1f4b8be0fffd0566352c8d.tar.gz
cpython-6f5a4efc0afaaf87eb1f4b8be0fffd0566352c8d.tar.bz2
Bug #132850 unix line terminator on windows.
Miserable hack to replace the previous miserable hack in maybe_pyc_file.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index a26781e..48b875e 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -580,18 +580,22 @@ maybe_pyc_file(FILE *fp, char* filename, char* ext, int closeit)
unsigned char buf[2];
/* 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.
+ 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).
*/
- 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);
+ 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;
}
return 0;