If not, would an lseek() followed by a read() do just as well?
No. lseek() and read() modify the file position/offset. pread() however does
*not* modify it. So to emulate pread() you would need something like:
ssize_t my_pread(int fd, void *buf, size_t count, off_t offset)
{
const off_t old_offset = lseek(fd, 0, SEEK_CUR); // missing error handling
lseek(fd, offset, SEEK_SET); // missing error handling
const ssize_t ret = read(fd, buf, count);
lseek(fd, old_offset, SEEK_SET); // missing error handling
return ret;
}
--
---> Dirk Jagdmann
----> http://cubic.org/~doj
-----> http://llg.cubic.org