summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-10-30 23:03:32 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-10-30 23:03:32 (GMT)
commitdd8059f0781d5af09b25ee5a0683c16cf5ff4d2a (patch)
tree9bf572acd447a20f60e2729fcab9fe25b8ad5f94 /Modules
parente329d1af1351a3f4b29ba0437e9220f70c29a390 (diff)
downloadcpython-dd8059f0781d5af09b25ee5a0683c16cf5ff4d2a.zip
cpython-dd8059f0781d5af09b25ee5a0683c16cf5ff4d2a.tar.gz
cpython-dd8059f0781d5af09b25ee5a0683c16cf5ff4d2a.tar.bz2
#3626: On cygwin, starting "python z" would not display any error message:
printf("%ls") fails if the wide string is 1 char long :-(
Diffstat (limited to 'Modules')
-rw-r--r--Modules/main.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Modules/main.c b/Modules/main.c
index 5a84cc2..6fdc33a 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -564,8 +564,17 @@ Py_Main(int argc, wchar_t **argv)
if (sts==-1 && filename!=NULL) {
if ((fp = _wfopen(filename, L"r")) == NULL) {
- fprintf(stderr, "%ls: can't open file '%ls': [Errno %d] %s\n",
- argv[0], filename, errno, strerror(errno));
+ 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>");
+ fprintf(stderr, "%ls: can't open file '%s': [Errno %d] %s\n",
+ argv[0], cfilename, errno, strerror(errno));
return 2;
}