summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-11 15:04:41 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-07-11 15:04:41 (GMT)
commitb28ed92dd0e46db1ba14d76375c7b0a7186249e3 (patch)
tree30146855fbb0a9717b85591143b3f0d60a5dfa5e /Modules/posixmodule.c
parent0d63f1228de60b9b4d0fcb765a18eabc41295127 (diff)
downloadcpython-b28ed92dd0e46db1ba14d76375c7b0a7186249e3.zip
cpython-b28ed92dd0e46db1ba14d76375c7b0a7186249e3.tar.gz
cpython-b28ed92dd0e46db1ba14d76375c7b0a7186249e3.tar.bz2
Issue #21932: os.read() now uses a :c:func:`Py_ssize_t` type instead of
:c:type:`int` for the size to support reading more than 2 GB at once. On Windows, the size is truncted to INT_MAX. As any call to os.read(), the OS may read less bytes than the number of requested bytes.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 899618f..b7acbc3 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -7989,11 +7989,18 @@ Read a file descriptor.");
static PyObject *
posix_read(PyObject *self, PyObject *args)
{
- int fd, size;
+ int fd;
+ Py_ssize_t size;
Py_ssize_t n;
PyObject *buffer;
- if (!PyArg_ParseTuple(args, "ii:read", &fd, &size))
+ if (!PyArg_ParseTuple(args, "in:read", &fd, &size))
return NULL;
+ if (!_PyVerify_fd(fd))
+ return posix_error();
+#ifdef MS_WINDOWS
+ if (size > INT_MAX)
+ size = INT_MAX;
+#endif
if (size < 0) {
errno = EINVAL;
return posix_error();
@@ -8001,12 +8008,12 @@ posix_read(PyObject *self, PyObject *args)
buffer = PyBytes_FromStringAndSize((char *)NULL, size);
if (buffer == NULL)
return NULL;
- if (!_PyVerify_fd(fd)) {
- Py_DECREF(buffer);
- return posix_error();
- }
Py_BEGIN_ALLOW_THREADS
+#ifdef MS_WINDOWS
+ n = read(fd, PyBytes_AS_STRING(buffer), (int)size);
+#else
n = read(fd, PyBytes_AS_STRING(buffer), size);
+#endif
Py_END_ALLOW_THREADS
if (n < 0) {
Py_DECREF(buffer);