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

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Tue, 6 Aug 2013 17:19:23 -0700
On Aug 6, 2013, at 3:57 PM, Dirk Jagdmann <doj@xxxxxxxxx> wrote:

>> 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:

If you do an absolute lseek() before each read(), and no other code uses the file descriptor, an lseek() followed by a read() *would* do as well.  The only things the routine in question does with the FD (which is static to the routine) are

	(attempt to) open it if it's not already open;

	read it with

		ret = pread(fd, buf, sizeof(buf)-1, 0);
		if (ret <= 0)
			return FALSE;

so that could be replaced by

		if (lseek(fd, 0, SEEK_SET) == -1)
			return FALSE;
		ret = read(fd, buf, sizeof(buf)-1);
		if (ret <= 0)
			return FALSE;