$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r49413 - in sandbox/SOC/2006/process/trunk/boost/process: . detail
From: jmmv84_at_[hidden]
Date: 2008-10-20 19:52:25
Author: jmmv
Date: 2008-10-20 19:52:25 EDT (Mon, 20 Oct 2008)
New Revision: 49413
URL: http://svn.boost.org/trac/boost/changeset/49413
Log:
Avoid using getcwd(NULL, 0) because this is not portable.
Text files modified: 
   sandbox/SOC/2006/process/trunk/boost/process/context.hpp          |    12 ++++--------                            
   sandbox/SOC/2006/process/trunk/boost/process/detail/posix_ops.hpp |    35 +++++++++++++++++++++++++++++++++++     
   2 files changed, 39 insertions(+), 8 deletions(-)
Modified: sandbox/SOC/2006/process/trunk/boost/process/context.hpp
==============================================================================
--- sandbox/SOC/2006/process/trunk/boost/process/context.hpp	(original)
+++ sandbox/SOC/2006/process/trunk/boost/process/context.hpp	2008-10-20 19:52:25 EDT (Mon, 20 Oct 2008)
@@ -1,7 +1,7 @@
 //
 // Boost.Process
 //
-// Copyright (c) 2006 Julio M. Merino Vidal.
+// Copyright (c) 2006, 2008 Julio M. Merino Vidal.
 //
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at
@@ -24,6 +24,8 @@
 
 #if defined(BOOST_PROCESS_POSIX_API)
 #   include <errno.h>
+#
+#   include <boost/process/detail/posix_ops.hpp>
 #elif defined(BOOST_PROCESS_WIN32_API)
 #   include <tchar.h>
 #   include <windows.h>
@@ -82,13 +84,7 @@
 basic_work_directory_context< Path >::basic_work_directory_context(void)
 {
 #if defined(BOOST_PROCESS_POSIX_API)
-    const char* buf = ::getcwd(NULL, 0);
-    if (buf == NULL)
-        boost::throw_exception
-            (system_error
-             ("boost::process::context::context",
-              "getcwd(2) failed", errno));
-    m_work_directory = buf;
+    m_work_directory = detail::get_work_directory< Path >();
 #elif defined(BOOST_PROCESS_WIN32_API)
     DWORD length = ::GetCurrentDirectory(0, NULL);
     TCHAR* buf = new TCHAR[length * sizeof(TCHAR)];
Modified: sandbox/SOC/2006/process/trunk/boost/process/detail/posix_ops.hpp
==============================================================================
--- sandbox/SOC/2006/process/trunk/boost/process/detail/posix_ops.hpp	(original)
+++ sandbox/SOC/2006/process/trunk/boost/process/detail/posix_ops.hpp	2008-10-20 19:52:25 EDT (Mon, 20 Oct 2008)
@@ -132,6 +132,41 @@
 // ------------------------------------------------------------------------
 
 //!
+//! \brief Gets the current work directory.
+//!
+//! Returns the path to the current work directory, without imposing any
+//! limits on its size as the native getcwd(2) does.  Note that calling
+//! getcwd(NULL, 0) is not portable, hence why we have this auxiliary
+//! function.
+//!
+template< class Path >
+inline
+Path
+get_work_directory(void)
+{
+    size_t buflen = 256;
+    boost::scoped_array< char > buf(new char[buflen]);
+    char *res;
+    do {
+        res = ::getcwd(buf.get(), buflen);
+        if (res == NULL) {
+            if (errno == ERANGE) {
+                buflen *= 2;
+                buf.reset(new char[buflen]);
+            } else {
+                boost::throw_exception
+                    (system_error
+                     ("boost::process::detail::posix_ops::get_work_directory",
+                      "getcwd(2) failed", errno));
+            }
+        }
+    } while (res == NULL);
+    return Path(buf.get());
+}
+
+// ------------------------------------------------------------------------
+
+//!
 //! Holds a mapping between native file descriptors and their corresponding
 //! pipes to set up communication between the parent and the %child process.
 //!