diff Modules/getpath.c @ 63962:7be5916333df

Create _Py_wchar2char() function, reverse of _Py_char2wchar() * Use _Py_wchar2char() in _wstat() and _Py_wfopen() * Document _Py_char2wchar()
author Victor Stinner <victor.stinner@haypocalc.com>
date Fri, 13 Aug 2010 23:29:08 +0000
parents 4742e7aea2f5
children ab6946972b7f
line wrap: on
line diff
--- a/Modules/getpath.c	Fri Aug 13 22:25:01 2010 +0000
+++ b/Modules/getpath.c	Fri Aug 13 23:29:08 2010 +0000
@@ -139,13 +139,16 @@
 static int
 _wstat(const wchar_t* path, struct stat *buf)
 {
-    char fname[PATH_MAX];
-    size_t res = wcstombs(fname, path, sizeof(fname));
-    if (res == (size_t)-1) {
+    int err;
+    char *fname;
+    fname = _Py_wchar2char(path);
+    if (fname == NULL) {
         errno = EINVAL;
         return -1;
     }
-    return stat(fname, buf);
+    err = stat(fname, buf);
+    PyMem_Free(fname);
+    return err;
 }
 #endif