Hacker News new | ask | show | jobs
by jra_samba_org 2227 days ago
Well pread/pwrite have the same return values, and historically for disk reads they block or return a device error.

pread only returns a short value on EOF.

2 comments

Well, the man page does say that "The readv() system call works just like read(2) except that multiple buffers are filled".

If we go to read(2) we find "It is not an error if [the return value] is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now [...], or because read() was interrupted by a signal."

As an outsider, I'd never rely on this returning the requested number of bytes. If I required N bytes, I'd write use a read loop.

But I do agree that the RWF_NOWAIT flag mentioned in your other comment doesn't help, as it suggests the default is to block.

Well, or EINTR if your signal handlers are not SA_RESTART.
For EINTR it never returns a short read, as the only way to see EINTR is a return of -1 with errno==EINTR.

We handle signals fine.

Sure, I was imprecise. A signal can cause a read to return a short result.