Split `stout/os/lseek.hpp` into Windows and POSIX files.

Review: https://reviews.apache.org/r/66427


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e7d4b3a7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e7d4b3a7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e7d4b3a7

Branch: refs/heads/master
Commit: e7d4b3a7a34c4431277c1e8d40697bd634a7d1bd
Parents: 9e93d0e
Author: Andrew Schwartzmeyer <[email protected]>
Authored: Fri Mar 16 22:35:36 2018 -0700
Committer: Andrew Schwartzmeyer <[email protected]>
Committed: Tue May 1 18:36:04 2018 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  2 ++
 3rdparty/stout/include/stout/os/lseek.hpp       | 28 +++------------
 3rdparty/stout/include/stout/os/posix/lseek.hpp | 36 ++++++++++++++++++++
 .../stout/include/stout/os/windows/lseek.hpp    | 36 ++++++++++++++++++++
 4 files changed, 79 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e7d4b3a7/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am 
b/3rdparty/stout/include/Makefile.am
index 87e951d..b2fc52e 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -136,6 +136,7 @@ nobase_include_HEADERS =                    \
   stout/os/posix/kill.hpp                      \
   stout/os/posix/killtree.hpp                  \
   stout/os/posix/ls.hpp                                \
+  stout/os/posix/lseek.hpp                     \
   stout/os/posix/mkdir.hpp                     \
   stout/os/posix/mkdtemp.hpp                   \
   stout/os/posix/mktemp.hpp                    \
@@ -178,6 +179,7 @@ nobase_include_HEADERS =                    \
   stout/os/windows/kill.hpp                    \
   stout/os/windows/killtree.hpp                        \
   stout/os/windows/ls.hpp                      \
+  stout/os/windows/lseek.hpp                   \
   stout/os/windows/mkdir.hpp                   \
   stout/os/windows/mktemp.hpp                  \
   stout/os/windows/mkdtemp.hpp                 \

http://git-wip-us.apache.org/repos/asf/mesos/blob/e7d4b3a7/3rdparty/stout/include/stout/os/lseek.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/lseek.hpp 
b/3rdparty/stout/include/stout/os/lseek.hpp
index 77fe272..d888f52 100644
--- a/3rdparty/stout/include/stout/os/lseek.hpp
+++ b/3rdparty/stout/include/stout/os/lseek.hpp
@@ -13,32 +13,14 @@
 #ifndef __STOUT_OS_LSEEK_HPP__
 #define __STOUT_OS_LSEEK_HPP__
 
-#ifdef __WINDOWS__
-#include <io.h>
-#else
-#include <unistd.h>
-#endif
-
-#include <stout/error.hpp>
-#include <stout/try.hpp>
-
-#include <stout/os/int_fd.hpp>
-
-namespace os {
 
-inline Try<off_t> lseek(int_fd fd, off_t offset, int whence)
-{
+// For readability, we minimize the number of #ifdef blocks in the code by
+// splitting platform specific system calls into separate directories.
 #ifdef __WINDOWS__
-  off_t result = ::_lseek(fd.crt(), offset, whence);
+#include <stout/os/windows/lseek.hpp>
 #else
-  off_t result = ::lseek(fd, offset, whence);
-#endif
-  if (result < 0) {
-    return ErrnoError();
-  }
-  return result;
-}
+#include <stout/os/posix/lseek.hpp>
+#endif // __WINDOWS__
 
-} // namespace os {
 
 #endif // __STOUT_OS_LSEEK_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/e7d4b3a7/3rdparty/stout/include/stout/os/posix/lseek.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/lseek.hpp 
b/3rdparty/stout/include/stout/os/posix/lseek.hpp
new file mode 100644
index 0000000..7b2e7b7
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/lseek.hpp
@@ -0,0 +1,36 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_POSIX_LSEEK_HPP__
+#define __STOUT_OS_POSIX_LSEEK_HPP__
+
+#include <unistd.h>
+
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+
+#include <stout/os/int_fd.hpp>
+
+namespace os {
+
+inline Try<off_t> lseek(int_fd fd, off_t offset, int whence)
+{
+  off_t result = ::lseek(fd, offset, whence);
+  if (result < 0) {
+    return ErrnoError();
+  }
+  return result;
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_LSEEK_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/e7d4b3a7/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
new file mode 100644
index 0000000..d34c022
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/lseek.hpp
@@ -0,0 +1,36 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#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/os/int_fd.hpp>
+
+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();
+  }
+  return result;
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_LSEEK_HPP__

Reply via email to