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

The logic remained the same, just with the Windows code removed from
the POSIX code, and vice versa.

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


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

Branch: refs/heads/master
Commit: 8b7798f31ea37077e5091d279fcf352a01577366
Parents: d4a903a
Author: Andrew Schwartzmeyer <[email protected]>
Authored: Thu Mar 15 15:27:32 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/open.hpp        | 45 ++--------------
 3rdparty/stout/include/stout/os/posix/open.hpp  | 47 +++++++++++++++++
 .../stout/include/stout/os/windows/open.hpp     | 55 ++++++++++++++++++++
 4 files changed, 108 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8b7798f3/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am 
b/3rdparty/stout/include/Makefile.am
index 52f81a8..87e951d 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -139,6 +139,7 @@ nobase_include_HEADERS =                    \
   stout/os/posix/mkdir.hpp                     \
   stout/os/posix/mkdtemp.hpp                   \
   stout/os/posix/mktemp.hpp                    \
+  stout/os/posix/open.hpp                      \
   stout/os/posix/pagesize.hpp                  \
   stout/os/posix/pipe.hpp                      \
   stout/os/posix/read.hpp                      \
@@ -180,6 +181,7 @@ nobase_include_HEADERS =                    \
   stout/os/windows/mkdir.hpp                   \
   stout/os/windows/mktemp.hpp                  \
   stout/os/windows/mkdtemp.hpp                 \
+  stout/os/windows/open.hpp                    \
   stout/os/windows/pagesize.hpp                        \
   stout/os/windows/pipe.hpp                    \
   stout/os/windows/read.hpp                    \

http://git-wip-us.apache.org/repos/asf/mesos/blob/8b7798f3/3rdparty/stout/include/stout/os/open.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/open.hpp 
b/3rdparty/stout/include/stout/os/open.hpp
index 4dc5b08..66f75dc 100644
--- a/3rdparty/stout/include/stout/os/open.hpp
+++ b/3rdparty/stout/include/stout/os/open.hpp
@@ -13,51 +13,14 @@
 #ifndef __STOUT_OS_OPEN_HPP__
 #define __STOUT_OS_OPEN_HPP__
 
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <string>
-
-#include <stout/error.hpp>
-#include <stout/nothing.hpp>
-#include <stout/try.hpp>
-
-#include <stout/os/close.hpp>
-#include <stout/os/fcntl.hpp>
-#include <stout/os/int_fd.hpp>
 
+// For readability, we minimize the number of #ifdef blocks in the code by
+// splitting platform specific system calls into separate directories.
 #ifdef __WINDOWS__
-#include <stout/internal/windows/longpath.hpp>
-#endif // __WINDOWS__
-
-#ifndef O_CLOEXEC
-#error "missing O_CLOEXEC support on this platform"
-// NOTE: On Windows, `fnctl.hpp` defines `O_CLOEXEC` to a no-op.
-#endif
-
-namespace os {
-
-inline Try<int_fd> open(const std::string& path, int oflag, mode_t mode = 0)
-{
-#ifdef __WINDOWS__
-  std::wstring longpath = ::internal::windows::longpath(path);
-  // By default, Windows will perform "text translation" meaning that it will
-  // automatically write CR/LF instead of LF line feeds. To prevent this, and
-  // use the POSIX semantics, we open with `O_BINARY`.
-  //
-  // Also by default, we will mimic the Windows (non-CRT) APIs and make all
-  // opened handles non-inheritable.
-  int_fd fd = ::_wopen(longpath.data(), oflag | O_BINARY | O_NOINHERIT, mode);
+#include <stout/os/windows/open.hpp>
 #else
-  int_fd fd = ::open(path.c_str(), oflag, mode);
+#include <stout/os/posix/open.hpp>
 #endif // __WINDOWS__
-  if (fd < 0) {
-    return ErrnoError();
-  }
-
-  return fd;
-}
 
-} // namespace os {
 
 #endif // __STOUT_OS_OPEN_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/8b7798f3/3rdparty/stout/include/stout/os/posix/open.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/open.hpp 
b/3rdparty/stout/include/stout/os/posix/open.hpp
new file mode 100644
index 0000000..0843782
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/open.hpp
@@ -0,0 +1,47 @@
+// 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_OPEN_HPP__
+#define __STOUT_OS_POSIX_OPEN_HPP__
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+
+#include <stout/os/close.hpp>
+#include <stout/os/fcntl.hpp>
+#include <stout/os/int_fd.hpp>
+
+#ifndef O_CLOEXEC
+#error "missing O_CLOEXEC support on this platform"
+#endif
+
+namespace os {
+
+inline Try<int_fd> open(const std::string& path, int oflag, mode_t mode = 0)
+{
+  int_fd fd = ::open(path.c_str(), oflag, mode);
+  if (fd < 0) {
+    return ErrnoError();
+  }
+
+  return fd;
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_OPEN_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/8b7798f3/3rdparty/stout/include/stout/os/windows/open.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/open.hpp 
b/3rdparty/stout/include/stout/os/windows/open.hpp
new file mode 100644
index 0000000..9598fdd
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/open.hpp
@@ -0,0 +1,55 @@
+// 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_OPEN_HPP__
+#define __STOUT_OS_WINDOWS_OPEN_HPP__
+
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+#include <stout/windows.hpp>  // For `mode_t`.
+
+#include <stout/os/close.hpp>
+#include <stout/os/fcntl.hpp> // For `oflag` values.
+#include <stout/os/int_fd.hpp>
+
+#include <stout/internal/windows/longpath.hpp>
+
+#ifndef O_CLOEXEC
+#error "missing O_CLOEXEC support on this platform"
+// NOTE: On Windows, `fnctl.hpp` defines `O_CLOEXEC` to a no-op.
+#endif
+
+namespace os {
+
+inline Try<int_fd> open(const std::string& path, int oflag, mode_t mode = 0)
+{
+  std::wstring longpath = ::internal::windows::longpath(path);
+  // By default, Windows will perform "text translation" meaning that it will
+  // automatically write CR/LF instead of LF line feeds. To prevent this, and
+  // use the POSIX semantics, we open with `O_BINARY`.
+  //
+  // Also by default, we will mimic the Windows (non-CRT) APIs and make all
+  // opened handles non-inheritable.
+  int_fd fd = ::_wopen(longpath.data(), oflag | O_BINARY | O_NOINHERIT, mode);
+  if (fd < 0) {
+    return ErrnoError();
+  }
+
+  return fd;
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_OPEN_HPP__

Reply via email to