Issue #10350: Read and save errno before calling a function which might overwrite it.

Original patch by Hallvard B Furuseth.
This commit is contained in:
Antoine Pitrou 2011-12-16 12:28:32 +01:00
parent 87448819ab
commit c345ce1a69
7 changed files with 33 additions and 12 deletions

View file

@ -654,13 +654,14 @@ Py_Main(int argc, wchar_t **argv)
if (fp == NULL) {
char *cfilename_buffer;
const char *cfilename;
int err = errno;
cfilename_buffer = _Py_wchar2char(filename, NULL);
if (cfilename_buffer != NULL)
cfilename = cfilename_buffer;
else
cfilename = "<unprintable file name>";
fprintf(stderr, "%ls: can't open file '%s': [Errno %d] %s\n",
argv[0], cfilename, errno, strerror(errno));
argv[0], cfilename, err, strerror(err));
if (cfilename_buffer)
PyMem_Free(cfilename_buffer);
return 2;