summaryrefslogtreecommitdiff
path: root/src/KM_fileio.cpp
diff options
context:
space:
mode:
authorjhurst <jhurst@cinecert.com>2015-10-07 16:58:03 +0000
committerjhurst <>2015-10-07 16:58:03 +0000
commit2bf9e844a7eb0e22e9fc4fe4d152ad9a4818dfcf (patch)
tree3cd1fedea250c47bd679b6d2823400248c09e561 /src/KM_fileio.cpp
parentaf6a1e4ef13dcf5811ccd9eb6b63d21bdc88dc70 (diff)
port
Diffstat (limited to 'src/KM_fileio.cpp')
-rw-r--r--src/KM_fileio.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/KM_fileio.cpp b/src/KM_fileio.cpp
index 5149d35..ed8aa67 100644
--- a/src/KM_fileio.cpp
+++ b/src/KM_fileio.cpp
@@ -43,6 +43,11 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define _rmdir rmdir
#endif
+// only needed by GetExecutablePath()
+#if defined(KM_MACOSX)
+#include <mach-o/dyld.h>
+#endif
+
using namespace Kumu;
#ifdef KM_WIN32
@@ -626,6 +631,55 @@ Kumu::PathMatchGlob::Match(const std::string& s) const {
#endif
+
+//------------------------------------------------------------------------------------------
+
+#define X_BUFSIZE 1024
+
+//
+std::string
+Kumu::GetExecutablePath(const std::string& default_path)
+{
+ char path[X_BUFSIZE] = {0};
+ bool success = false;
+
+#if defined(KM_WIN32)
+ DWORD size = X_BUFSIZE;
+ DWORD rc = GetModuleFileName(0, path, size);
+ success = ( rc != 0 );
+#elif defined(KM_MACOSX)
+ uint32_t size = X_BUFSIZE;
+ int rc = _NSGetExecutablePath(path, &size);
+ success = ( rc != -1 );
+#elif defined(__linux__)
+ size_t size = X_BUFSIZE;
+ ssize_t rc = readlink("/proc/self/exe", path, size);
+ success = ( rc != -1 );
+#elif defined(__OpenBSD__) || defined(__FreeBSD__)
+ size_t size = X_BUFSIZE;
+ ssize_t rc = readlink("/proc/curproc/file", path, size);
+ success = ( rc != -1 );
+#elif defined(__FreeBSD__)
+ size_t size = X_BUFSIZE;
+ ssize_t rc = readlink("/proc/curproc/file", path, size);
+ success = ( rc != -1 );
+#elif defined(__NetBSD__)
+ size_t size = X_BUFSIZE;
+ ssize_t rc = readlink("/proc/curproc/file", path, size);
+ success = ( rc != -1 );
+#else
+#error GetExecutablePath --> Create a method for obtaining the executable name
+#endif
+
+ if ( success )
+ {
+ return Kumu::PathMakeCanonical(path);
+ }
+
+ return default_path;
+}
+
+
//------------------------------------------------------------------------------------------
// portable aspects of the file classes