|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64942 - sandbox/SOC/2010/process/boost/process
From: boris_at_[hidden]
Date: 2010-08-21 19:06:57
Author: bschaeling
Date: 2010-08-21 19:06:55 EDT (Sat, 21 Aug 2010)
New Revision: 64942
URL: http://svn.boost.org/trac/boost/changeset/64942
Log:
Added detection of PATH_MAX to self::get_work_dir()
Text files modified:
sandbox/SOC/2010/process/boost/process/config.hpp | 10 ++++------
sandbox/SOC/2010/process/boost/process/self.hpp | 22 +++++++++++++++++-----
2 files changed, 21 insertions(+), 11 deletions(-)
Modified: sandbox/SOC/2010/process/boost/process/config.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/config.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/config.hpp 2010-08-21 19:06:55 EDT (Sat, 21 Aug 2010)
@@ -39,12 +39,10 @@
* Specifies the system's maximal supported path length.
*
* The macro BOOST_PROCESS_POSIX_PATH_MAX is set to a positive integer
- * value which specifies the system's maximal supported path length.
- * By default it is set to 259. You should set the macro to PATH_MAX
- * which should be defined in limits.h provided by your operating system
- * if you experience problems when calling boost::process::self::get_work_dir().
- * The function tries to retrieve the maximal supported path length but uses
- * BOOST_PROCESS_POSIX_PATH_MAX if it fails. Please note that the function is
+ * value which specifies the system's maximal supported path length. It is
+ * only used if neither PATH_MAX nor _PC_PATH_MAX and HAVE_PATHCONF are defined.
+ * The maximal supported path length is required by
+ * boost::process::self::get_work_dir(). Please note that this function is
* also called by the constructor of boost::process::context.
*/
# define BOOST_PROCESS_POSIX_PATH_MAX 259
Modified: sandbox/SOC/2010/process/boost/process/self.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/self.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/self.hpp 2010-08-21 19:06:55 EDT (Sat, 21 Aug 2010)
@@ -26,6 +26,7 @@
# include <boost/scoped_array.hpp>
# include <errno.h>
# include <unistd.h>
+# include <limits.h>
# if defined(__APPLE__)
# include <crt_externs.h>
# endif
@@ -129,19 +130,30 @@
*/
static std::string get_work_dir()
{
-#if defined(BOOST_POSIX_API)
+#if defined(BOOST_POSIX_API)
+#if defined(PATH_MAX)
+ char buffer[PATH_MAX];
+ char *cwd = buffer;
+ long size = PATH_MAX;
+#elif defined(_PC_PATH_MAX)
errno = 0;
- long size = pathconf(".", _PC_PATH_MAX);
+ long size = pathconf("/", _PC_PATH_MAX);
if (size == -1 && errno)
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("pathconf(2) failed");
else if (size == -1)
size = BOOST_PROCESS_POSIX_PATH_MAX;
BOOST_ASSERT(size > 0);
- boost::scoped_array<char> cwd(new char[size]);
- if (!getcwd(cwd.get(), size))
+ boost::scoped_array<char> buffer(new char[size]);
+ char *cwd = buffer.get();
+#else
+ char buffer[BOOST_PROCESS_POSIX_PATH_MAX];
+ char *cwd = buffer;
+ long size = BOOST_PROCESS_POSIX_PATH_MAX;
+#endif
+ if (!getcwd(cwd, size))
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("getcwd(2) failed");
BOOST_ASSERT(cwd[0] != '\0');
- return cwd.get();
+ return cwd;
#elif defined(BOOST_WINDOWS_API)
BOOST_ASSERT(MAX_PATH > 0);
char cwd[MAX_PATH];
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk