summaryrefslogtreecommitdiff
path: root/Modules/_io/fileio.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_io/fileio.c')
-rw-r--r--Modules/_io/fileio.c55
1 files changed, 18 insertions, 37 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 8f174a7edb..ec320f79b9 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -464,34 +464,6 @@ fileio_seekable(fileio *self)
return PyBool_FromLong((long) self->seekable);
}
-static Py_ssize_t
-internal_read(int fd, void *buf, size_t count)
-{
- Py_ssize_t n;
-
- Py_BEGIN_ALLOW_THREADS
- errno = 0;
- n = read(fd, buf, count);
-#ifdef EIO
- /* Issue #5380: when reading past the end of a pipe created by
- openpty(), EIO can be set. Make it an EOF instead, so that
- the normal technique of testing for an empty string can be used.
- */
- if (n == -1 && errno == EIO) {
- if (isatty(fd)) {
- n = 0;
- errno = 0;
- }
- else {
- /* isatty() set errno, restore its value */
- errno = EIO;
- }
- }
-#endif
- Py_END_ALLOW_THREADS
- return n;
-}
-
static PyObject *
fileio_readinto(fileio *self, PyObject *args)
{
@@ -506,9 +478,12 @@ fileio_readinto(fileio *self, PyObject *args)
if (!PyArg_ParseTuple(args, "w*", &pbuf))
return NULL;
- if (_PyVerify_fd(self->fd))
- n = internal_read(self->fd, pbuf.buf, pbuf.len);
- else
+ if (_PyVerify_fd(self->fd)) {
+ Py_BEGIN_ALLOW_THREADS
+ errno = 0;
+ n = read(self->fd, pbuf.buf, pbuf.len);
+ Py_END_ALLOW_THREADS
+ } else
n = -1;
PyBuffer_Release(&pbuf);
if (n < 0) {
@@ -585,9 +560,12 @@ fileio_readall(fileio *self)
break;
}
}
- n = internal_read(self->fd,
- PyBytes_AS_STRING(result) + total,
- newsize - total);
+ Py_BEGIN_ALLOW_THREADS
+ errno = 0;
+ n = read(self->fd,
+ PyBytes_AS_STRING(result) + total,
+ newsize - total);
+ Py_END_ALLOW_THREADS
if (n == 0)
break;
if (n < 0) {
@@ -639,9 +617,12 @@ fileio_read(fileio *self, PyObject *args)
return NULL;
ptr = PyBytes_AS_STRING(bytes);
- if (_PyVerify_fd(self->fd))
- n = internal_read(self->fd, ptr, size);
- else
+ if (_PyVerify_fd(self->fd)) {
+ Py_BEGIN_ALLOW_THREADS
+ errno = 0;
+ n = read(self->fd, ptr, size);
+ Py_END_ALLOW_THREADS
+ } else
n = -1;
if (n < 0) {