
30 Jan
2005
30 Jan
'05
1:18 a.m.
At 07:30 AM 1/28/2005, Jonathan Wakely wrote:
However, in that case there's a comment about the implementation:
// TODO: Ask POSIX experts if this is the best way to copy a file
Now, I'm no POSIX expert, but I believe the loop used:
ssize_t sz; while ( (sz = ::read( infile, buf.get(), buf_sz )) > 0 && (sz = ::write( outfile, buf.get(), sz )) > 0 ) {}
can result in lost data if write(2) only does a partial write, which might happen if the write is interrupted by a signal. I think it should loop on the writes too, until write() has returned sz in total.
Hum... Reading the POSIX spec, it looks like you are right. ::write() will also only do a partial write if the process runs out of disk space, for example. Thanks, --Beman