[Python-checkins] r85468 - python/branches/py3k/Modules/main.c

victor.stinner python-checkins at python.org
Thu Oct 14 12:51:24 CEST 2010


Author: victor.stinner
Date: Thu Oct 14 12:51:24 2010
New Revision: 85468

Log:
Py_Main() uses _Py_wchar2char() to encode the filename in error messages


Modified:
   python/branches/py3k/Modules/main.c

Modified: python/branches/py3k/Modules/main.c
==============================================================================
--- python/branches/py3k/Modules/main.c	(original)
+++ python/branches/py3k/Modules/main.c	Thu Oct 14 12:51:24 2010
@@ -637,19 +637,19 @@
         }
 
         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) {


More information about the Python-checkins mailing list