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.
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.
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.
Philip