summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-10-28 18:34:56 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-28 10:56:49 (GMT)
commitab6bac1ee3ba4ebf4dfc8dc1a3ae6783756c48c9 (patch)
treedc69a9a658683b7f3caa81a06040dcbd4d87acc8 /Swiften/Base
parent34eb7f55fbdd1566ee117738f3a423354ce1b45c (diff)
downloadswift-ab6bac1ee3ba4ebf4dfc8dc1a3ae6783756c48c9.zip
swift-ab6bac1ee3ba4ebf4dfc8dc1a3ae6783756c48c9.tar.bz2
Added swiften-config.
Diffstat (limited to 'Swiften/Base')
-rw-r--r--Swiften/Base/Paths.cpp47
-rw-r--r--Swiften/Base/Paths.h16
-rw-r--r--Swiften/Base/SConscript1
3 files changed, 64 insertions, 0 deletions
diff --git a/Swiften/Base/Paths.cpp b/Swiften/Base/Paths.cpp
new file mode 100644
index 0000000..c1dbef2
--- /dev/null
+++ b/Swiften/Base/Paths.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Base/Paths.h>
+#include <Swiften/Base/Platform.h>
+
+#if defined(SWIFTEN_PLATFORM_MACOSX)
+#include <mach-o/dyld.h>
+#elif defined(SWIFTEN_PLATFORM_LINUX)
+#include <unistd.h>
+#elif defined(SWIFTEN_PLATFORM_WINDOWS)
+#include <windows.h>
+#endif
+
+#include <Swiften/Base/ByteArray.h>
+
+namespace Swift {
+
+boost::filesystem::path Paths::getExecutablePath() {
+#if defined(SWIFTEN_PLATFORM_MACOSX)
+ ByteArray path;
+ uint32_t size = 4096;
+ path.resize(size);
+ if (_NSGetExecutablePath(path.getData(), &size) == 0) {
+ return boost::filesystem::path(path.toString().getUTF8Data()).parent_path();
+ }
+#elif defined(SWIFTEN_PLATFORM_LINUX)
+ ByteArray path;
+ path.resize(4096);
+ size_t size = readlink("/proc/self/exe", path.getData(), path.getSize());
+ if (size > 0) {
+ path.resize(size);
+ return boost::filesystem::path(path.toString().getUTF8Data()).parent_path();
+ }
+#elif defined(SWIFTEN_PLATFORM_WINDOWS)
+ ByteArray data;
+ data.resize(2048);
+ GetModuleFileName(NULL, data.getData(), data.getSize());
+ return boost::filesystem::path(data.toString().getUTF8Data()).parent_path();
+#endif
+ return boost::filesystem::path();
+}
+
+}
diff --git a/Swiften/Base/Paths.h b/Swiften/Base/Paths.h
new file mode 100644
index 0000000..06c6aeb
--- /dev/null
+++ b/Swiften/Base/Paths.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/filesystem.hpp>
+
+namespace Swift {
+ class Paths {
+ public:
+ static boost::filesystem::path getExecutablePath();
+ };
+}
diff --git a/Swiften/Base/SConscript b/Swiften/Base/SConscript
index a0984e5..fb58d34 100644
--- a/Swiften/Base/SConscript
+++ b/Swiften/Base/SConscript
@@ -3,6 +3,7 @@ Import("swiften_env")
objects = swiften_env.StaticObject([
"ByteArray.cpp",
"Error.cpp",
+ "Paths.cpp",
"IDGenerator.cpp",
"String.cpp",
"sleep.cpp",