Replacing the system call pread() with lseek()/xread()/lseek() sequence.
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>
Stefan-W. Hahn committed
Jan 9, 2007 at 22:04 UTC
6900679c2f6d937a5a6ef616869c8887690ad19d
3 files changed
+30
Makefile
+7
@@ -69,6 +69,9 @@ all:
69
#
70
# Define NO_MMAP if you want to avoid mmap.
71
#
72
+# Define NO_PREAD if you have a problem with pread() system call (e.g.
73
+# cygwin.dll before v1.5.22).
74
+#
75
# Define NO_FAST_WORKING_DIRECTORY if accessing objects in pack files is
76
# generally faster on your platform than accessing the working directory.
77
#
@@ -523,6 +526,10 @@ ifdef NO_MMAP
526
COMPAT_CFLAGS += -DNO_MMAP
527
COMPAT_OBJS += compat/mmap.o
528
endif
529
+ifdef NO_PREAD
530
+ COMPAT_CFLAGS += -DNO_PREAD
531
+ COMPAT_OBJS += compat/pread.o
532
+endif
533
ifdef NO_FAST_WORKING_DIRECTORY
534
BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY
535
endif
compat/pread.c
new
+18
@@ -0,0 +1,18 @@
1
+#include "../git-compat-util.h"
2
+
3
+ssize_t git_pread(int fd, void *buf, size_t count, off_t offset)
4
+{
5
+ off_t current_offset;
6
+ ssize_t rc;
7
+
8
+ current_offset = lseek(fd, 0, SEEK_CUR);
9
+
10
+ if (lseek(fd, offset, SEEK_SET) < 0)
11
+ return -1;
12
+
13
+ rc = read_in_full(fd, buf, count);
14
+
15
+ if (current_offset != lseek(fd, current_offset, SEEK_SET))
16
+ return -1;
17
+ return rc;
18
+}
git-compat-util.h
+5
@@ -107,6 +107,11 @@ extern int git_munmap(void *start, size_t length);
107
#define DEFAULT_PACKED_GIT_LIMIT \
108
((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))
109
110
+#ifdef NO_PREAD
111
+#define pread git_pread
112
+extern ssize_t git_pread(int fd, void *buf, size_t count, off_t offset);
113
+#endif
114
+
115
#ifdef NO_SETENV
116
#define setenv gitsetenv
117
extern int gitsetenv(const char *, const char *, int);