I am trying to read files that are simultaneously being written to disk. I need to read pieces of a certain size. If the read size is less than a certain size, I would like it to not read the file (something like what ungetc does, instead for char []) and try again. Adding to bytes already read is not an option for me.
How is this possible?
I tried to save the current position with:
FILE *fd = fopen("test.txt","r+");
fpos_t position;
fgetpos (fd, &position);
and then reading the file and returning the pointer to its randomized position.
numberOfBytes = fread(buff, sizeof(unsigned char), desiredSize, fd)
if (numberByBytes < desiredSize) {
fsetpos (fd, &position);
}
But it does not seem to work.
source
share