summaryrefslogtreecommitdiff
path: root/lib/System
diff options
context:
space:
mode:
Diffstat (limited to 'lib/System')
-rw-r--r--lib/System/CMakeLists.txt2
-rw-r--r--lib/System/Host.cpp3
-rw-r--r--lib/System/Unix/Path.inc24
-rw-r--r--lib/System/Win32/Path.inc7
4 files changed, 31 insertions, 5 deletions
diff --git a/lib/System/CMakeLists.txt b/lib/System/CMakeLists.txt
index 2945e33d5b1c..a56a1f78bb72 100644
--- a/lib/System/CMakeLists.txt
+++ b/lib/System/CMakeLists.txt
@@ -42,5 +42,5 @@ add_llvm_library(LLVMSystem
)
if( BUILD_SHARED_LIBS AND NOT WIN32 )
- target_link_libraries(LLVMSystem dl)
+ target_link_libraries(LLVMSystem ${CMAKE_DL_LIBS})
endif()
diff --git a/lib/System/Host.cpp b/lib/System/Host.cpp
index 37591a57b070..e112698349ee 100644
--- a/lib/System/Host.cpp
+++ b/lib/System/Host.cpp
@@ -22,6 +22,9 @@
#ifdef LLVM_ON_WIN32
#include "Win32/Host.inc"
#endif
+#ifdef _MSC_VER
+#include <intrin.h>
+#endif
//===----------------------------------------------------------------------===//
//
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index 89285b48132f..ff1497a5c6df 100644
--- a/lib/System/Unix/Path.inc
+++ b/lib/System/Unix/Path.inc
@@ -335,7 +335,7 @@ getprogpath(char ret[PATH_MAX], const char *bin)
free(pv);
return (NULL);
}
-#endif
+#endif // __FreeBSD__
/// GetMainExecutable - Return the path to the main executable, given the
/// value of argv[0] from program startup.
@@ -348,7 +348,8 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {
uint32_t size = sizeof(exe_path);
if (_NSGetExecutablePath(exe_path, &size) == 0) {
char link_path[MAXPATHLEN];
- return Path(std::string(realpath(exe_path, link_path)));
+ if (realpath(exe_path, link_path))
+ return Path(std::string(link_path));
}
#elif defined(__FreeBSD__)
char exe_path[PATH_MAX];
@@ -370,7 +371,8 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {
// If the filename is a symlink, we need to resolve and return the location of
// the actual executable.
char link_path[MAXPATHLEN];
- return Path(std::string(realpath(DLInfo.dli_fname, link_path)));
+ if (realpath(DLInfo.dli_fname, link_path))
+ return Path(std::string(link_path));
#endif
return Path();
}
@@ -454,6 +456,20 @@ Path::canWrite() const {
}
bool
+Path::isRegularFile() const {
+ // Get the status so we can determine if its a file or directory
+ struct stat buf;
+
+ if (0 != stat(path.c_str(), &buf))
+ return false;
+
+ if (S_ISREG(buf.st_mode))
+ return true;
+
+ return false;
+}
+
+bool
Path::canExecute() const {
if (0 != access(path.c_str(), R_OK | X_OK ))
return false;
@@ -723,7 +739,7 @@ Path::createTemporaryFileOnDisk(bool reuse_current, std::string* ErrMsg) {
bool
Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
- // Get the status so we can determin if its a file or directory
+ // Get the status so we can determine if its a file or directory
struct stat buf;
if (0 != stat(path.c_str(), &buf)) {
MakeErrMsg(ErrStr, path + ": can't get status of file");
diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc
index 573369e97d49..634fbc7650b3 100644
--- a/lib/System/Win32/Path.inc
+++ b/lib/System/Win32/Path.inc
@@ -357,6 +357,13 @@ Path::canExecute() const {
return attr != INVALID_FILE_ATTRIBUTES;
}
+bool
+Path::isRegularFile() const {
+ if (isDirectory())
+ return false;
+ return true;
+}
+
std::string
Path::getLast() const {
// Find the last slash