Am 13.02.2014 19:38, schrieb Zachary Turner:

> The only reason ReOpenFile is necessary at 
> all is because some code somewhere is mixing read-styles against the same 
> fd.
> 

I don't understand...ReadFile with OVERLAPPED parameter doesn't modify the 
HANDLE's file position, so you should be able to mix read()/pread() however you 
like (as long as read() is only called from one thread).

I tried without ReOpenFile and it seems to work like a charm, or am I missing 
something?

----8<----
ssize_t mingw_pread(int fd, void *buf, size_t count, off64_t offset)
{
        DWORD bytes_read;
        OVERLAPPED overlapped;
        memset(&overlapped, 0, sizeof(overlapped));
        overlapped.Offset = (DWORD) offset;
        overlapped.OffsetHigh = (DWORD) (offset >> 32);

        if (!ReadFile((HANDLE) _get_osfhandle(fd), buf, count, &bytes_read,
            &overlapped)) {
                errno = err_win_to_posix(GetLastError());
                return -1;
        }
        return (ssize_t) bytes_read;
}

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to