Here is a piece of code :
Here's my problem. Often, I'm calling this piece of code to read a block of data from a file pointed to by diskp. Now on certain occasions (namely, when diskp is opened with "r+b" permission), fread fails (and reads 0 elements) and it therefore gets into the if statement. Furthermore, everytime it fails it always outputs "Error in disk read : Buffer write failed". This is where I'm confused. How can my program get so far ? From what I grasp from fread's man page, it should fail if it reaches EOF or gets an error (in which case ERRNO is set). But I believe I've testing both of these, but neither of these conditions corresponding to what my program is telling me. So how come fread is failing ? Is there some other, "alternate" method for fread to fail or something ?Code:if ((t = (fread(buffer,BLOCK_SIZ,1,diskp))) != 1) // Read from disk to buffer { if(feof(diskp) != 0) { fprintf(stdout,"End of file reached. %d Blocks read.\n",f); return t; } if((err_num = ferror(diskp)) != 0) { fprintf(stderr,"%s\n",strerror(err_num)); } fprintf(stderr,"Error in disk read : Buffer write failed. %d\n",f); return 0; }
Thanks in advance.



LinkBack URL
About LinkBacks


