Loop if necessary when reading

If pread64() reads fewer bytes than required, continue reading until
the requested buffer size has been read or an error occurs.

This is part of fixing #1038.

Signed-off-by: Stephen Kitt <steve@sk2.org>