git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Replacing the system call pread() with lseek()/xread()/lseek() sequence.

From
Junio C Hamano <junkio@cox.net>
Date
Jan 9, 2007, 20:21 UTC
Message-ID
<7v1wm4kl24.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<41319.3372231492$1168368741@news.gmane.org>
"Stefan-W. Hahn" <stefan.hahn@s-hahn.de> writes:
Show 5 quoted lines
> Using cygwin with cygwin.dll before 1.5.22 the system call pread() is buggy.
> This patch introduces NO_PREAD. If NO_PREAD is set git uses a sequence of
> lseek()/xread()/lseek() to emulate pread.
>
> Signed-off-by: Stefan-W. Hahn <stefan.hahn@s-hahn.de>
Thanks.
> +# Define NO_PREAD if you have a problem with pread() system call (i.e.
> +# cygwin.dll before v1.5.22).
> +#
I would have preferred e.g. not i.e..
Show 9 quoted lines
> diff --git a/compat/pread.c b/compat/pread.c
> new file mode 100644
> index 0000000..cd1da87
> --- /dev/null
> +++ b/compat/pread.c
> @@ -0,0 +1,15 @@
> +#include "../git-compat-util.h"
> +
> +ssize_t git_pread(int fd,void *buf,size_t count,off_t offset)
Style: s/,/, /; applies to git-compat-util.h as well.
Show 7 quoted lines
> +{
> +        off_t current_offset = lseek(fd, 0, SEEK_CUR);
> +
> +        if (lseek(fd, offset, SEEK_SET) < 0)
> +                return EINVAL;
> +
> +        ssize_t rc=xread(fd, buf, count);
Style: please don't have declaration after statement.  Yes, it
is in the more recent ANSI, but the rest of git has avoided it
so far and having the decls upfront makes it easier to read.
I do not think you would want to return EINVAL.

Andy's read_in_full() is now on 'master' so please use it instead to avoid short read.

Previous: Stefan-W. Hahn
Message 3 of 3 in “Test for failing pread() on cygwin.”
  1. Test for failing pread() on cygwin.Stefan-W. Hahn, Jan 9, 2007
  2. Replacing the system call pread() with lseek()/xread()/lseek() sequence.Stefan-W. Hahn, Jan 9, 2007
  3. Junio C HamanoJan 9, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.