+
+/*
+ * We'd like to use pread/pwrite for our file accesses, but unfortunately it
+ * isn't simple at all since all libc's until glibc 2.1 don't define it.
+ */
+
+#ifndef SHERLOCK_HAVE_PREAD
+
+#ifdef __linux__
+#define SHERLOCK_HAVE_PREAD
+#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
+/* glibc 2.1 or newer -> pread/pwrite supported automatically */
+#ifdef SHERLOCK_CONFIG_LFS
+/* but have to use the 64-bit versions explicitly */
+#define sh_pread pread64
+#define sh_pwrite pwrite64
+#else
+#define sh_pread pread
+#define sh_pwrite pwrite
+#endif
+#elif defined(i386) && defined(__GLIBC__)
+/* glibc 2.0 on i386 -> call syscalls directly */
+#include <asm/unistd.h>
+#include <syscall-list.h>
+#include <sys/types.h>
+#include <unistd.h>
+#ifndef SYS_pread
+#define SYS_pread 180
+#endif
+static int sh_pread(unsigned int fd, void *buf, size_t size, loff_t where)
+{ return syscall(SYS_pread, fd, buf, size, where); }
+#ifndef SYS_pwrite
+#define SYS_pwrite 181
+#endif
+static int sh_pwrite(unsigned int fd, void *buf, size_t size, loff_t where)
+{ return syscall(SYS_pwrite, fd, buf, size, where); }
+#elif defined(i386)
+/* old libc on i386 -> call syscalls directly the old way */
+#include <asm/unistd.h>
+#include <errno.h>
+static _syscall4(int, pread, unsigned int, fd, void *, buf, size_t, size, loff_t, where);
+static _syscall4(int, pwrite, unsigned int, fd, void *, buf, size_t, size, loff_t, where);
+#define sh_pread pread
+#define sh_pwrite pwrite
+#else
+#undef SHERLOCK_HAVE_PREAD
+#endif
+#endif /* __linux__ */
+
+#endif /* !SHERLOCK_HAVE_PREAD */
+