Subject: Re: [PATCH] Replacing the system call pread() with real mmap().

From: "Shawn O. Pearce" <[email-masked]>
Date: Sun, 7 Jan 2007 06:24:45 -0500

"Stefan-W. Hahn" <[email-masked]> wrote:
> +# Define NO_PREAD if you have a problem with pread() system call (i.e.
> +# cygwin.dll before v1.5.22). This needs NO_MMAP not to be set, because pread()
> +# is emulated using mmap.

Better to emulate pread using lseek/xread/lseek:

	off_t p = lseek(fd, offset, SEEK_SET);
	xread(fd, buf, count);
	lseek(fd, p, SEEK_SET);

If you look at the history for contrib/mmap.c you will see an
implementation like that before it was called git_mmap().

This works OK in Git as we only ever have one thread, therefore
there is no race condition during the seek/read/seek calls.  Its also
usually faster on platforms like Mac OS X where mmap() is horrible.
If the platform is lacking a good pread() it may also be the case
that it lacks a good mmap(); in this case it would be desirable to
set both NO_MMAP and NO_PREAD.

-- 
Shawn.