Skip to content

Commit 108e65b

Browse files
committed
Add clean code
1 parent 9315688 commit 108e65b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Modules/posixmodule.c

+14
Original file line numberDiff line numberDiff line change
@@ -11342,6 +11342,20 @@ os_read_impl(PyObject *module, int fd, Py_ssize_t length)
1134211342

1134311343
length = Py_MIN(length, _PY_READ_MAX);
1134411344

11345+
static long page_size;
11346+
if (page_size == 0)
11347+
page_size = sysconf(_SC_PAGE_SIZE);
11348+
11349+
#ifndef MS_WINDOWS
11350+
if (length > page_size * 16) {
11351+
struct stat statbuffer;
11352+
fstat(fd, &statbuffer);
11353+
if (S_ISFIFO(statbuffer.st_mode)) {
11354+
length = Py_MIN(page_size* 16, length);
11355+
}
11356+
}
11357+
#endif
11358+
1134511359
buffer = PyBytes_FromStringAndSize((char *)NULL, length);
1134611360
if (buffer == NULL)
1134711361
return NULL;

0 commit comments

Comments
 (0)