File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -747,14 +747,16 @@ _io_FileIO_readall_impl(fileio *self)
747747 bufsize = SMALLCHUNK ;
748748 }
749749 else {
750- /* This is probably a real file, so we try to allocate a
751- buffer one byte larger than the rest of the file. If the
752- calculation is right then we should get EOF without having
753- to enlarge the buffer. */
750+ /* This is probably a real file. */
754751 if (end > _PY_READ_MAX - 1 ) {
755752 bufsize = _PY_READ_MAX ;
756753 }
757754 else {
755+ /* In order to detect end of file, need a read() of at
756+ least 1 byte which returns size 0. Oversize the buffer
757+ by 1 byte so the I/O can be completed with two read()
758+ calls (one for all data, one for EOF) without needing
759+ to resize the buffer. */
758760 bufsize = (size_t )end + 1 ;
759761 }
760762
You can’t perform that action at this time.
0 commit comments