summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorStefan-W. Hahn <stefan.hahn@s-hahn.de>2007-01-09 22:04:12 +0100
committerJunio C Hamano <junkio@cox.net>2007-01-09 16:40:40 -0800
commit6900679c2f6d937a5a6ef616869c8887690ad19d (patch)
tree138e2f17ba6cd89646c5098ce526e51a4dce5359 /compat
parent0bdb28c9ccd85b1c606664154b6f6d39a4c315fd (diff)
downloadgit-6900679c2f6d937a5a6ef616869c8887690ad19d.tar.gz
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>
Diffstat (limited to 'compat')
-rw-r--r--compat/pread.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/compat/pread.c b/compat/pread.c
new file mode 100644
index 0000000000..978cac4ec9
--- /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;
+}