]> granicus.if.org Git - python/commitdiff
os.statvfs() encodes the filename to the filesystem encoding
authorVictor Stinner <victor.stinner@haypocalc.com>
Tue, 20 Sep 2011 02:04:33 +0000 (04:04 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Tue, 20 Sep 2011 02:04:33 +0000 (04:04 +0200)
Modules/posixmodule.c

index 2fc509d315f406bbfe66bcf9e50d53cc3df7ff29..25e7f0dbefb58bda3eaece0676a4219f08e6b4d9 100644 (file)
@@ -8071,16 +8071,20 @@ Perform a statvfs system call on the given path.");
 static PyObject *
 posix_statvfs(PyObject *self, PyObject *args)
 {
-    char *path;
+    PyObject *path;
     int res;
     struct statvfs st;
-    if (!PyArg_ParseTuple(args, "s:statvfs", &path))
+    if (!PyArg_ParseTuple(args, "O&:statvfs", PyUnicode_FSConverter, &path))
         return NULL;
     Py_BEGIN_ALLOW_THREADS
-    res = statvfs(path, &st);
+    res = statvfs(PyBytes_AS_STRING(path), &st);
     Py_END_ALLOW_THREADS
-    if (res != 0)
-        return posix_error_with_filename(path);
+    if (res != 0) {
+        posix_error_with_filename(PyBytes_AS_STRING(path));
+        Py_DECREF(path);
+        return NULL;
+    }
+    Py_DECREF(path);
 
     return _pystatvfs_fromstructstatvfs(st);
 }