c - read an empty file with fread -
i trying read empty file fread. before created file blocksize of 4096 , amount of 40 blocks. @ moment know these blocks "empty" if read file in code below cannot tell wether empty or not. mean expecting nread null or that. know have compare nread with? thank you!
int test() { char buf[4096]; file *file; size_t nread; file = fopen("out/abc.store", "r"); if (file) { while ((nread = fread(buf, 1, sizeof buf, file)) > 0) fwrite(buf, 1, nread, stdout); if (ferror(file)) { /*error handling*/ } fclose(file); }
edit:
i created file that:
char *content=(char*)malloc(uintblocksize*uintblockcount); memset(content,0,uintblocksize*uintblockcount); ... while (i!=0) { check=fwrite(content,uintblocksize, 1, storefile); if (check!=1) return 1; i--; }
check see if fread
returned 0. documentation (here):
the total number of elements read returned.
Comments
Post a Comment