I am having trouble to understand why lseek
function is useful.
Assuming I got a parameter like this given to me from the user:
off_t offset = 10;
And I wanted to read from the offset 100 bytes.
I can use pread
like this:
void * buf = malloc(100);
if (buf == NULL) { exit(1);}
int res = pread(file_id, buf, 100, offset);
On the other hand, I understand I can set the file with lseek
like this:
off_t seek = lseek(file_id, offset, SEEK_SET);
So I believe I achieve reading using pread
already. What did I miss regarding lseek
in what it can do to help me read the file?