Kaydet (Commit) 6f5a4efc authored tarafından Tim Peters's avatar Tim Peters

Bug #132850 unix line terminator on windows.

Miserable hack to replace the previous miserable hack in maybe_pyc_file.
üst 657ba27d
...@@ -580,18 +580,22 @@ maybe_pyc_file(FILE *fp, char* filename, char* ext, int closeit) ...@@ -580,18 +580,22 @@ maybe_pyc_file(FILE *fp, char* filename, char* ext, int closeit)
unsigned char buf[2]; unsigned char buf[2];
/* Mess: In case of -x, the stream is NOT at its start now, /* Mess: In case of -x, the stream is NOT at its start now,
and ungetc() was used to push back the first newline, and ungetc() was used to push back the first newline,
which makes the current stream position formally undefined which makes the current stream position formally undefined,
until that newline is read back. So first we getc(), so and a x-platform nightmare.
that ftell() is well-defined. 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; int ispyc = 0;
rewind(fp); if (ftell(fp) == 0) {
ispyc = fread(buf, 1, 2, fp) == 2 && if (fread(buf, 1, 2, fp) == 2 &&
((unsigned int)buf[1]<<8 | buf[0]) == halfmagic; ((unsigned int)buf[1]<<8 | buf[0]) == halfmagic)
fseek(fp, currentpos, SEEK_SET); ispyc = 1;
ungetc(maybepushedback, fp); rewind(fp);
}
return ispyc; return ispyc;
} }
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment