On 23/03/04 21:01 +0530, Philip S Tellis wrote:
Sometime Today, Devdas Bhagat assembled some asciibets to say:
/*
- The OP should tell us why he/she is using read and write instead of
- fread and fwrite, or perhaps rename to move the file instead
*/
irrelevant. fread/fwrite won't work on file descriptors. They require FILE pointers. open/creat/socket return file descriptors.
The whole point is that the OP is copying a file from one place on local disk to another.
while (fd) {
and who sets fd to 0?
if (n < sizeof(buff)) { /* Short read, eof? */
this is a short read. it does not mean eof. eof is signalled by a return value of 0. n < requested size just means that fewer bytes than requested were available at the time.
Yup. In the current scenario though, this should not happen. Like I said, bad code sample.
close_check = close(fd); /* Close file */
don't close here. close only if n == 0. If n < 0, check for errno of EINTR or EAGAIN, and redo the read.
Lots more work to fix that piece of code.
Devdas Bhagat