facebook/hhvm — pull request #1333 by danslo (2013-12-10 17:43:00+00:00)
Title: fix stream_get_contents when no offset is specified

File does its own internal buffering and uses m_readpos, m_writepos,
m_position for the purpose of keeping track of file offsets. This means
that current (PHP) position is not in sync with the underlying file
descriptor (m_fd).

This works fine, were it not for the fact that ext_stream calls directly
into pure virtual method readImpl that generally lives in PlainFile
and works directly on the file descriptor that might contain an
invalid (buffered-ahead) position.

This pull request does several things:
- Remove default value 0 for File::read(int64_t length), since that
implementation returns earlier for 0 values anyway.
- Implement an overloaded method File::read() that reads the remainder
of the file (until EOF) by using proper File::m_* properties.
- Make ext_stream call into File::read instead of PlainFile::readImpl.

Obviously, comments on this are very much appreciated!