diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-14 10:51:24 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-14 10:51:24 (GMT) |
commit | 9a6692f6d7784365ae07094694c754d2b153b719 (patch) | |
tree | fdae5df60c38fad66a30724340e845ab4c80888f | |
parent | 89f3ad10d2bf762126bee3c5fadf19c3c7bf2f52 (diff) | |
download | cpython-9a6692f6d7784365ae07094694c754d2b153b719.zip cpython-9a6692f6d7784365ae07094694c754d2b153b719.tar.gz cpython-9a6692f6d7784365ae07094694c754d2b153b719.tar.bz2 |
Py_Main() uses _Py_wchar2char() to encode the filename in error messages
-rw-r--r-- | Modules/main.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/Modules/main.c b/Modules/main.c index c9499ac..bbf695f 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -637,19 +637,19 @@ Py_Main(int argc, wchar_t **argv) } if (sts==-1 && filename!=NULL) { - if ((fp = _Py_wfopen(filename, L"r")) == NULL) { - char cfilename[PATH_MAX]; - size_t r = wcstombs(cfilename, filename, PATH_MAX); - if (r == PATH_MAX) - /* cfilename is not null-terminated; - * forcefully null-terminating it - * might break the shift state */ - strcpy(cfilename, "<file name too long>"); - if (r == ((size_t)-1)) - strcpy(cfilename, "<unprintable file name>"); + fp = _Py_wfopen(filename, L"r"); + if (fp == NULL) { + char *cfilename_buffer; + const char *cfilename; + cfilename_buffer = _Py_wchar2char(filename); + 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)); - + if (cfilename_buffer) + PyMem_Free(cfilename_buffer); return 2; } else if (skipfirstline) { |