ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Wireshark-dev: Re: [Wireshark-dev] [Wireshark-commits] rev 51169: / /trunk/epan/: app_mem_usage

From: Dirk Jagdmann <doj@xxxxxxxxx>
Date: Tue, 06 Aug 2013 15:57:41 -0700
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