Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2005-01-29 20:18:04


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk