Home page logo

wireshark logo Wireshark mailing list archives

Re: [Wireshark-commits] rev 51169: / /trunk/epan/: app_mem_usage.c
From: Guy Harris <guy () alum mit edu>
Date: Tue, 6 Aug 2013 17:19:23 -0700

On Aug 6, 2013, at 3:57 PM, Dirk Jagdmann <doj () cubic org> 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) 

        (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;
Sent via:    Wireshark-dev mailing list <wireshark-dev () wireshark org>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request () wireshark org?subject=unsubscribe

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]