< prev index next >
src/jdk.incubator.jpackage/macosx/native/common/MacSysInfo.cpp
Print this page
*** 21,36 ****
--- 21,63 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+ #include <sys/stat.h>
+ #include <unistd.h>
#include <mach-o/dyld.h>
#include "FileUtils.h"
#include "ErrorHandling.h"
namespace SysInfo {
+ tstring getRealPath(std::vector<char> in) {
+ std::vector<char> out(PATH_MAX);
+
+ struct stat sb;
+ if (lstat(in.data(), &sb) == -1) {
+ JP_THROW(tstrings::any() << "lstat(" << in.data()
+ << ") failed. Error: " << lastCRTError());
+ }
+
+ // readlink() will fail if called on real path, so if we have real path, then just
+ // use it
+ if (!S_ISLNK(sb.st_mode)) {
+ return tstring(in.data(), in.size() - 1 /* don't count trailing '0' */);
+ }
+
+ // Get real path, since _NSGetExecutablePath can return symbolic link
+ ssize_t len = readlink(in.data(), out.data(), PATH_MAX);
+ if (len < 0) {
+ JP_THROW(tstrings::any() << "readlink(" << in.data()
+ << ") failed. Error: " << lastCRTError());
+ }
+
+ return tstring(out.data(), len);
+ }
+
tstring getProcessModulePath() {
std::vector<char> buffer;
uint32_t bufferSize = 0;
do {
int len = _NSGetExecutablePath(buffer.data(), &bufferSize);
*** 42,52 ****
JP_THROW(tstrings::any() << "_NSGetExecutablePath() failed");
}
buffer.resize(bufferSize);
} while (true);
! tstring reply = tstring(buffer.data(),
! buffer.size() - 1 /* don't count trailing '0' */);
return FileUtils::toAbsolutePath(reply);
}
} // end of namespace SysInfo
--- 69,80 ----
JP_THROW(tstrings::any() << "_NSGetExecutablePath() failed");
}
buffer.resize(bufferSize);
} while (true);
!
! tstring reply = getRealPath(buffer);
!
return FileUtils::toAbsolutePath(reply);
}
} // end of namespace SysInfo
< prev index next >