Commit 2d1a9b95 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1321

Reopens ticket.
Cannot get handles (from _get_osfhandle) to work with ReadFile or WriteFile

git-svn-id: file:///svn/toku/tokudb.1032b@8373 c7de825b-a66e-492c-adef-691d508d4ae1
parent b2194b83
......@@ -4,36 +4,27 @@
#include <unistd.h>
#include <windows.h>
// Note: pread and pwrite are not thread safe on the same fildes as they
// rely on the file offset
int64_t
pread(int fildes, void *buf, size_t nbyte, int64_t offset) {
long handle;
OVERLAPPED win_offset = {0};
handle = _get_osfhandle(fildes);
win_offset.Offset = offset % (1LL<<32LL);
win_offset.OffsetHigh = offset / (1LL<<32LL);
DWORD bytes_read;
int64_t r = ReadFile(&handle, buf, nbyte, &bytes_read, &win_offset);
if (!r) r = GetLastError();
else r = bytes_read;
int64_t r = _lseeki64(fildes, offset, SEEK_SET);
if (r>=0) {
assert(r==offset);
r = read(fildes, buf, nbyte);
}
// printf("%s: %d %p %u %I64d %I64d\n", __FUNCTION__, fildes, buf, nbyte, offset, r); fflush(stdout);
return r;
}
int64_t
pwrite(int fildes, const void *buf, size_t nbyte, int64_t offset) {
long handle;
OVERLAPPED win_offset = {0};
handle = _get_osfhandle(fildes);
win_offset.Offset = offset % (1LL<<32LL);
win_offset.OffsetHigh = offset / (1LL<<32LL);
DWORD bytes_written;
int64_t r = WriteFile(&handle, buf, nbyte, &bytes_written, &win_offset);
if (!r) r = GetLastError();
else r = bytes_written;
int64_t r = _lseeki64(fildes, offset, SEEK_SET);
if (r>=0) {
assert(r==offset);
r = write(fildes, buf, nbyte);
}
// printf("%s: %d %p %u %I64d %I64d\n", __FUNCTION__, fildes, buf, nbyte, offset, r); fflush(stdout);
return r;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment