summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-04-10 21:06:59 (GMT)
committerGuido van Rossum <guido@python.org>2007-04-10 21:06:59 (GMT)
commit8742977b33f2af9b92265c1b332af0f6798bf2b6 (patch)
tree938cba4969aa85a38eaaf096b33c3a743b1bda2a /Modules
parent34d69e57e31763bdfcff77dc3689ec42a5228814 (diff)
downloadcpython-8742977b33f2af9b92265c1b332af0f6798bf2b6.zip
cpython-8742977b33f2af9b92265c1b332af0f6798bf2b6.tar.gz
cpython-8742977b33f2af9b92265c1b332af0f6798bf2b6.tar.bz2
truncate() returns the new size and position.
write() returns the number of bytes/characters written/buffered. FileIO.close() calls self.flush(). Implement readinto() for buffered readers. Tests th check all these. Test proper behavior of __enter__/__exit__.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_fileio.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Modules/_fileio.c b/Modules/_fileio.c
index 985fa81..97b2199 100644
--- a/Modules/_fileio.c
+++ b/Modules/_fileio.c
@@ -530,6 +530,9 @@ fileio_truncate(PyFileIOObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|O", &posobj))
return NULL;
+ if (posobj == Py_None)
+ posobj = NULL;
+
if (posobj == NULL)
whence = 1;
else
@@ -545,19 +548,22 @@ fileio_truncate(PyFileIOObject *self, PyObject *args)
pos = PyLong_Check(posobj) ?
PyLong_AsLongLong(posobj) : PyInt_AsLong(posobj);
#endif
- Py_DECREF(posobj);
- if (PyErr_Occurred())
+ if (PyErr_Occurred()) {
+ Py_DECREF(posobj);
return NULL;
+ }
Py_BEGIN_ALLOW_THREADS
errno = 0;
pos = ftruncate(fd, pos);
Py_END_ALLOW_THREADS
- if (errno < 0)
+ if (pos < 0) {
+ Py_DECREF(posobj);
PyErr_SetFromErrno(PyExc_IOError);
+ }
- Py_RETURN_NONE;
+ return posobj;
}
static char *