summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0bdb28c)
raw | patch | inline | side by side (parent: 0bdb28c)
author | Stefan-W. Hahn <stefan.hahn@s-hahn.de> | |
Tue, 9 Jan 2007 21:04:12 +0000 (22:04 +0100) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 10 Jan 2007 00:40:40 +0000 (16:40 -0800) |
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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Makefile | patch | blob | history | |
compat/pread.c | [new file with mode: 0644] | patch | blob |
git-compat-util.h | patch | blob | history |
diff --git a/Makefile b/Makefile
index 6c12bc64ac9da2bb9fafd2a6a88053dc82b7d6d3..43113e9e16937899332bcd24a88a2ae78ce65c97 100644 (file)
--- a/Makefile
+++ b/Makefile
#
# Define NO_MMAP if you want to avoid mmap.
#
+# Define NO_PREAD if you have a problem with pread() system call (e.g.
+# cygwin.dll before v1.5.22).
+#
# Define NO_FAST_WORKING_DIRECTORY if accessing objects in pack files is
# generally faster on your platform than accessing the working directory.
#
COMPAT_CFLAGS += -DNO_MMAP
COMPAT_OBJS += compat/mmap.o
endif
+ifdef NO_PREAD
+ COMPAT_CFLAGS += -DNO_PREAD
+ COMPAT_OBJS += compat/pread.o
+endif
ifdef NO_FAST_WORKING_DIRECTORY
BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY
endif
diff --git a/compat/pread.c b/compat/pread.c
--- /dev/null
+++ b/compat/pread.c
@@ -0,0 +1,18 @@
+#include "../git-compat-util.h"
+
+ssize_t git_pread(int fd, void *buf, size_t count, off_t offset)
+{
+ off_t current_offset;
+ ssize_t rc;
+
+ current_offset = lseek(fd, 0, SEEK_CUR);
+
+ if (lseek(fd, offset, SEEK_SET) < 0)
+ return -1;
+
+ rc = read_in_full(fd, buf, count);
+
+ if (current_offset != lseek(fd, current_offset, SEEK_SET))
+ return -1;
+ return rc;
+}
diff --git a/git-compat-util.h b/git-compat-util.h
index e023bf141363d87abfef358134e484ea85f32a15..f8d46d587bec2b4dbab0263fa3df97e60beb08e4 100644 (file)
--- a/git-compat-util.h
+++ b/git-compat-util.h
#define DEFAULT_PACKED_GIT_LIMIT \
((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))
+#ifdef NO_PREAD
+#define pread git_pread
+extern ssize_t git_pread(int fd, void *buf, size_t count, off_t offset);
+#endif
+
#ifdef NO_SETENV
#define setenv gitsetenv
extern int gitsetenv(const char *, const char *, int);