I need to access a file larger than 2 GB using C. During one run of the program, a variable number of bytes and the location of the next saved position will be read from the file. The next time the program starts, the file position is read and several bytes are read, starting from this point.
The complication is that sometimes a file can be “compressed” by copying it to a new file, with the exception of all bytes already read (I think that copying is the only way to do this). The number of deleted bytes in this way will also be saved.
I need to know the current position of the file from the initial launch in order to synchronize with another file. This should be easy, because it is simple (current_offset + deleted_bytes).
The reason is that fseek only uses long int indexes that limit the 2gb file, and fsetpos uses the fpos_t structure to index the position, which is not a number and cannot be converted back and forth to one. I don't know how to use a long int index to position files, which would be an ideal solution.
What should I do?
source
share