2 Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
3 (HOOMD-blue) Open Source Software License Copyright 2009-2014 The Regents of
4 the University of Michigan All rights reserved.
6 HOOMD-blue may contain modifications ("Contributions") provided, and to which
7 copyright is held, by various Contributors who have granted The Regents of the
8 University of Michigan the right to modify and/or distribute such Contributions.
10 You may redistribute, use, and create derivate works of HOOMD-blue, in source
11 and binary forms, provided you abide by the following conditions:
13 * Redistributions of source code must retain the above copyright notice, this
14 list of conditions, and the following disclaimer both in the code and
15 prominently in any materials provided with the distribution.
17 * Redistributions in binary form must reproduce the above copyright notice, this
18 list of conditions, and the following disclaimer in the documentation and/or
19 other materials provided with the distribution.
21 * All publications and presentations based on HOOMD-blue, including any reports
22 or published results obtained, in whole or in part, with HOOMD-blue, will
23 acknowledge its use according to the terms posted at the time of submission on:
24 http://codeblue.umich.edu/hoomd-blue/citations.html
26 * Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
27 http://codeblue.umich.edu/hoomd-blue/
29 * Apart from the above required attributions, neither the name of the copyright
30 holder nor the names of HOOMD-blue's contributors may be used to endorse or
31 promote products derived from this software without specific prior written
36 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
37 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
39 WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
41 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
42 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
43 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
46 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 // Maintainer: joaander
51 /*! \file PathUtils.cc
52 \brief Simple functions for dealing with paths
61 #include <mach-o/dyld.h>
68 #include <boost/version.hpp>
69 #include <boost/filesystem/operations.hpp>
70 #include <boost/filesystem/convenience.hpp>
72 #include "PathUtils.h"
77 getExePath uses different methods on different platforms. It identifies the real file for the running executable.
79 std::string
getExePath()
82 const unsigned int path_max
=PATH_MAX
;
84 const unsigned int path_max
=1024;
87 // exe path identification from: http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe
91 // ask darwin what our exe path is
94 uint32_t bufsize
= 1024;
95 int retval
= _NSGetExecutablePath(buf
, &bufsize
);
97 throw std::runtime_error("Unable to determine executable path");
99 // turn it into a real path
100 char *realbuf
= realpath(buf
, NULL
);
101 result
= std::string(realbuf
);
107 memset(buf
, 0, path_max
);
108 size_t bufsize
= path_max
;
109 size_t retval
= readlink("/proc/self/exe", buf
, bufsize
);
111 if (retval
== size_t(-1))
112 throw std::runtime_error("Unable to determine executable path");
114 result
= std::string(buf
);
117 #error Not implemented
118 // see the above link for a howto on implementing this. Not a high priority to do so because windows is deprecated
120 #error Not implemented
123 // the above routines get the actual executable. Return the path to it
124 #if (BOOST_VERSION >= 104400)
125 return boost::filesystem::path(result
).parent_path().string();
126 #elif (BOOST_VERSION <= 103500)
127 return boost::filesystem::path(result
).branch_path().native_file_string();
129 return boost::filesystem::path(result
).parent_path().native_file_string();