diff options
author | Guido van Rossum <guido@python.org> | 2007-04-12 22:55:07 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-04-12 22:55:07 (GMT) |
commit | dc0b1a106981ee204936221f4e0863bd1d7a6ba6 (patch) | |
tree | 102949af2918a30ac4da920751e994c0df4af702 /Modules/_fileio.c | |
parent | b6f1fdc90ca1f5826c5bd8e015a37563923144b5 (diff) | |
download | cpython-dc0b1a106981ee204936221f4e0863bd1d7a6ba6.zip cpython-dc0b1a106981ee204936221f4e0863bd1d7a6ba6.tar.gz cpython-dc0b1a106981ee204936221f4e0863bd1d7a6ba6.tar.bz2 |
Make a few more tests pass with the new I/O library.
Fix the truncate() semantics -- it should not affect the current position.
Switch wave.py/chunk.py to struct.unpack_from() to support bytes.
Don't use writelines() on binary files (test_fileinput.py).
Diffstat (limited to 'Modules/_fileio.c')
-rw-r--r-- | Modules/_fileio.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/Modules/_fileio.c b/Modules/_fileio.c index 97b2199..d524aa7 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -519,7 +519,7 @@ fileio_truncate(PyFileIOObject *self, PyObject *args) { PyObject *posobj = NULL; Py_off_t pos; - int fd, whence; + int fd; fd = self->fd; if (fd < 0) @@ -530,17 +530,14 @@ 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 - whence = 0; - - posobj = portable_lseek(fd, posobj, whence); - if (posobj == NULL) - return NULL; + if (posobj == Py_None || posobj == NULL) { + posobj = portable_lseek(fd, NULL, 1); + if (posobj == NULL) + return NULL; + } + else { + Py_INCREF(posobj); + } #if !defined(HAVE_LARGEFILE_SUPPORT) pos = PyInt_AsLong(posobj); |