Windows: Fixed `os::lseek()` to use `SetFilePointerEx()`. Note the TODO, we may want to synchronize this code later.
Review: https://reviews.apache.org/r/66428 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2d22336f Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2d22336f Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2d22336f Branch: refs/heads/master Commit: 2d22336f81378bea083f221690684a4ea826a6ec Parents: e7d4b3a Author: Andrew Schwartzmeyer <[email protected]> Authored: Fri Mar 16 22:39:04 2018 -0700 Committer: Andrew Schwartzmeyer <[email protected]> Committed: Tue May 1 18:36:04 2018 -0700 ---------------------------------------------------------------------- .../stout/include/stout/os/windows/lseek.hpp | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/2d22336f/3rdparty/stout/include/stout/os/windows/lseek.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/lseek.hpp b/3rdparty/stout/include/stout/os/windows/lseek.hpp index d34c022..c0ec71c 100644 --- a/3rdparty/stout/include/stout/os/windows/lseek.hpp +++ b/3rdparty/stout/include/stout/os/windows/lseek.hpp @@ -13,10 +13,9 @@ #ifndef __STOUT_OS_WINDOWS_LSEEK_HPP__ #define __STOUT_OS_WINDOWS_LSEEK_HPP__ -#include <io.h> - #include <stout/error.hpp> #include <stout/try.hpp> +#include <stout/windows.hpp> #include <stout/os/int_fd.hpp> @@ -24,11 +23,26 @@ namespace os { inline Try<off_t> lseek(int_fd fd, off_t offset, int whence) { - off_t result = ::_lseek(fd.crt(), offset, whence); - if (result < 0) { - return ErrnoError(); + // NOTE: The values for `SEEK_SET`, `SEEK_CUR`, and `SEEK_END` are + // 0, 1, 2, the same as `FILE_BEGIN`, `FILE_CURRENT`, and + // `FILE_END`. Thus we don't need to map them, and they can be + // casted to a `DWORD` safely. + + LARGE_INTEGER offset_; + offset_.QuadPart = offset; + + LARGE_INTEGER new_offset; + + // TODO(andschwa): This may need to be synchronized if users aren't + // careful about sharing their file handles among threads. + const BOOL result = + ::SetFilePointerEx(fd, offset_, &new_offset, static_cast<DWORD>(whence)); + + if (result == FALSE) { + return WindowsError(); } - return result; + + return static_cast<off_t>(new_offset.QuadPart); } } // namespace os {
