summaryrefslogtreecommitdiffstats
path: root/src/binary_location.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-10-20 04:17:36 +0000
committerDavid Robillard <d@drobilla.net>2008-10-20 04:17:36 +0000
commitc7d1bd354c0c109186793aeb00ad481a614ee76a (patch)
tree54cad29d91887905652b1c6db8c3f7497365a310 /src/binary_location.h
parentaa3af28d1e3a05f3e495bd08f07fef8427e1ca48 (diff)
downloadpatchage-c7d1bd354c0c109186793aeb00ad481a614ee76a.tar.gz
patchage-c7d1bd354c0c109186793aeb00ad481a614ee76a.tar.bz2
patchage-c7d1bd354c0c109186793aeb00ad481a614ee76a.zip
Add missing files.
Build wrapper scripts so bundle executable are runnable from anywhere. git-svn-id: http://svn.drobilla.net/lad/trunk/patchage@1691 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/binary_location.h')
-rw-r--r--src/binary_location.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/binary_location.h b/src/binary_location.h
new file mode 100644
index 0000000..9030e2c
--- /dev/null
+++ b/src/binary_location.h
@@ -0,0 +1,41 @@
+/* Find the location of the program in the filesytem.
+ * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _GNU_SOURCE
+ #define _GNU_SOURCE
+#endif
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+
+/** Return the absolute path of the binary.
+ * Returned value must be freed by caller.
+ */
+static char*
+binary_location()
+{
+ Dl_info dli;
+ dladdr((void*)&binary_location, &dli);
+
+ char* bin_loc = (char*)calloc(PATH_MAX, sizeof(char));
+ realpath(dli.dli_fname, bin_loc);
+
+ return bin_loc;
+}
+