check man read. On success, the number of bytes read is returned. abhijeet
On Tue, 2004-03-23 at 18:59, Devdas Bhagat wrote:
On 23/03/04 03:44 -0800, Linux User wrote:
<snip> > while(n = read(fd,buff,sizeof(buff)) > 0){ This will be parsed as while (n = (read(fd, buff, sizeof(buff)) > 0)) { The result of the bracket around read is 1, since the return value of read is > 0 and hence the condition evaluates to true.
/* Bad code follows */
/*
- 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
*/ while (fd) { n = read(fd, buff, sizeof(buff)); if (n = -1) { perror("Read failed: "); exit(n); }
if (n < sizeof(buff)) { /* Short read, eof? */ close_check = close(fd); /* Close file */ /* * We had an error while closing the file * Alert to see if the disk is full, or corrupted. */ if (close_check = -1) { perror("File close failed, disk full?: "); } }
/* Insert code for writes here */ }
Devdas Bhagat