Windows: Moved `os::getcwd` to its own file, `stout/os/getcwd.hpp`.

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


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

Branch: refs/heads/master
Commit: c1295c418f07ef9f78952d61e4f2e932cba6ba26
Parents: e24889e
Author: Alex Clemmer <[email protected]>
Authored: Mon Oct 26 15:43:51 2015 -0500
Committer: Joris Van Remoortere <[email protected]>
Committed: Wed Oct 28 17:11:03 2015 -0500

----------------------------------------------------------------------
 .../3rdparty/stout/include/Makefile.am          |  1 +
 .../3rdparty/stout/include/stout/os.hpp         |  1 +
 .../3rdparty/stout/include/stout/os/getcwd.hpp  | 52 ++++++++++++++++++++
 .../3rdparty/stout/include/stout/posix/os.hpp   | 24 ---------
 .../3rdparty/stout/include/stout/windows.hpp    |  7 +++
 .../3rdparty/stout/include/stout/windows/os.hpp |  6 ---
 6 files changed, 61 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c1295c41/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am 
b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index 45a33b0..79c9fe4 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -59,6 +59,7 @@ nobase_include_HEADERS =              \
   stout/os/fcntl.hpp                   \
   stout/os/fork.hpp                    \
   stout/os/ftruncate.hpp               \
+  stout/os/getcwd.hpp                  \
   stout/os/killtree.hpp                        \
   stout/os/linux.hpp                   \
   stout/os/posix/bootid.hpp            \

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1295c41/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 5b11ea0..ad2e1b5 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -77,6 +77,7 @@
 #include <stout/os/bootid.hpp>
 #include <stout/os/environment.hpp>
 #include <stout/os/fork.hpp>
+#include <stout/os/getcwd.hpp>
 #include <stout/os/killtree.hpp>
 #include <stout/os/ls.hpp>
 #include <stout/os/mktemp.hpp>

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1295c41/3rdparty/libprocess/3rdparty/stout/include/stout/os/getcwd.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/getcwd.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/getcwd.hpp
new file mode 100644
index 0000000..162f046
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/getcwd.hpp
@@ -0,0 +1,52 @@
+/**
+ * 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_GETCWD_HPP__
+#define __STOUT_OS_GETCWD_HPP__
+
+#include <stout/try.hpp>
+
+#ifdef __WINDOWS__
+#include <stout/windows.hpp> // To be certain we're using the right `getcwd`.
+#endif // __WINDOWS__
+
+
+namespace os {
+
+inline std::string getcwd()
+{
+  size_t size = 100;
+
+  while (true) {
+    char* temp = new char[size];
+    if (::getcwd(temp, size) == temp) {
+      std::string result(temp);
+      delete[] temp;
+      return result;
+    } else {
+      if (errno != ERANGE) {
+        delete[] temp;
+        return std::string();
+      }
+      size *= 2;
+      delete[] temp;
+    }
+  }
+
+  return std::string();
+}
+
+} // namespace os {
+
+
+#endif // __STOUT_OS_GETCWD_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1295c41/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
index 9a38733..f4bf383 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
@@ -460,30 +460,6 @@ inline Try<Nothing> su(const std::string& user)
 }
 
 
-inline std::string getcwd()
-{
-  size_t size = 100;
-
-  while (true) {
-    char* temp = new char[size];
-    if (::getcwd(temp, size) == temp) {
-      std::string result(temp);
-      delete[] temp;
-      return result;
-    } else {
-      if (errno != ERANGE) {
-        delete[] temp;
-        return std::string();
-      }
-      size *= 2;
-      delete[] temp;
-    }
-  }
-
-  return std::string();
-}
-
-
 inline Result<std::string> user(Option<uid_t> uid = None())
 {
   if (uid.isNone()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1295c41/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
index 4fdd34d..aa2e16e 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
@@ -203,6 +203,13 @@ decltype(_close(fd))
 }
 
 
+inline auto getcwd(char* path, int maxlen) ->
+decltype(_getcwd(path, maxlen))
+{
+  return _getcwd(path, maxlen);
+}
+
+
 inline auto mkdir(const char* path, mode_t mode) ->
 decltype(_mkdir(path))
 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1295c41/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
index eec8f0f..ecf0e14 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
@@ -165,12 +165,6 @@ inline Try<Nothing> su(const std::string& user)
 }
 
 
-inline std::string getcwd()
-{
-  UNIMPLEMENTED;
-}
-
-
 inline Result<std::string> user(Option<uid_t> uid = None())
 {
   UNIMPLEMENTED;

Reply via email to