summaryrefslogtreecommitdiff
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-19 22:53:20 +0100
committerVictor Stinner <victor.stinner@gmail.com>2015-03-19 22:53:20 +0100
commit66aab0c4b5b6b328aebc115f96275e7dcd114f8b (patch)
treec607e0019befcb199fb8f916038d01a0b3b9a5f3 /Objects/fileobject.c
parent9eb57c5fa50ed2f57d9320bb575371868316b5f2 (diff)
downloadcpython-git-66aab0c4b5b6b328aebc115f96275e7dcd114f8b.tar.gz
Issue #23708: Add _Py_read() and _Py_write() functions to factorize code handle
EINTR error and special cases for Windows. These functions now truncate the length to PY_SSIZE_T_MAX to have a portable and reliable behaviour. For example, read() result is undefined if counter is greater than PY_SSIZE_T_MAX on Linux.
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 596f909755..6f2e35166b 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -383,26 +383,15 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
Py_RETURN_NONE;
}
- if (!PyArg_ParseTuple(args, "s", &c)) {
+ if (!PyArg_ParseTuple(args, "s", &c))
return NULL;
- }
- n = strlen(c);
- Py_BEGIN_ALLOW_THREADS
- errno = 0;
-#ifdef MS_WINDOWS
- if (n > INT_MAX)
- n = INT_MAX;
- n = write(self->fd, c, (int)n);
-#else
- n = write(self->fd, c, n);
-#endif
- Py_END_ALLOW_THREADS
-
- if (n < 0) {
- if (errno == EAGAIN)
+ n = _Py_write(self->fd, c, strlen(c));
+ if (n == -1) {
+ if (errno == EAGAIN) {
+ PyErr_Clear();
Py_RETURN_NONE;
- PyErr_SetFromErrno(PyExc_IOError);
+ }
return NULL;
}