diff options
author | Guido van Rossum <guido@python.org> | 2007-04-10 21:06:59 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-04-10 21:06:59 (GMT) |
commit | 8742977b33f2af9b92265c1b332af0f6798bf2b6 (patch) | |
tree | 938cba4969aa85a38eaaf096b33c3a743b1bda2a /Modules | |
parent | 34d69e57e31763bdfcff77dc3689ec42a5228814 (diff) | |
download | cpython-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.c | 14 |
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 * |