summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrzej Hunt <andrzej.hunt@collabora.com>2014-07-28 20:23:03 +0200
committerAndrzej Hunt <andrzej.hunt@collabora.com>2014-07-29 07:11:20 +0200
commit9e7bdb422d12d8be4b76eaf065e3aea8f9055f12 (patch)
treea1854228e61d9904edae4cb3239a3b1846db2917 /include
parent300845922eec7a28bc1da337acd21f138685d759 (diff)
Kill the libreofficekit static library / shim.c.
It looks like the cleanest method of getting lok_init into a LibreOfficeKitInit.h header (in a c89 compatible way) is to have it as a static function. (inline is only available in C99 or later -- this is actually available on Linux which is the only place that we can actually use lok_init anyways currently, however given we have to keep c89 for the C code (for MSVC) compatibility, selectively enabling c99 would likely be more messy.) Change-Id: I0493e7a68ed5397479220bb6ba8c3db870b6dd32
Diffstat (limited to 'include')
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h2
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitInit.h96
2 files changed, 96 insertions, 2 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 675eabc5ae5e..9c746348eac9 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -105,8 +105,6 @@ struct _LibreOfficeKitDocumentClass
#endif // LOK_USE_UNSTABLE_API
};
-LibreOfficeKit* lok_init (const char* pInstallPath);
-
#ifdef __cplusplus
}
#endif
diff --git a/include/LibreOfficeKit/LibreOfficeKitInit.h b/include/LibreOfficeKit/LibreOfficeKitInit.h
new file mode 100644
index 000000000000..ef01b1c84d31
--- /dev/null
+++ b/include/LibreOfficeKit/LibreOfficeKitInit.h
@@ -0,0 +1,96 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_DESKTOP_INC_LIBREOFFICEKIT_INIT_H
+#define INCLUDED_DESKTOP_INC_LIBREOFFICEKIT_INIT_H
+
+#include "LibreOfficeKit.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#if defined(__linux__) || defined(_AIX)
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dlfcn.h>
+#ifdef _AIX
+# include <sys/ldr.h>
+#endif
+
+#define TARGET_LIB "lib" "sofficeapp" ".so"
+#define TARGET_MERGED_LIB "lib" "mergedlo" ".so"
+
+typedef LibreOfficeKit *(HookFunction)( const char *install_path);
+
+static LibreOfficeKit *lok_init( const char *install_path )
+{
+ char *imp_lib;
+ size_t partial_length;
+ void *dlhandle;
+ HookFunction *pSym;
+
+ if (!install_path)
+ return NULL;
+
+ // allocate large enough buffer
+ partial_length = strlen(install_path);
+ imp_lib = (char *) malloc(partial_length + sizeof(TARGET_LIB) + sizeof(TARGET_MERGED_LIB) + 2);
+ if (!imp_lib)
+ {
+ fprintf( stderr, "failed to open library : not enough memory\n");
+ return NULL;
+ }
+
+ strcpy(imp_lib, install_path);
+
+ imp_lib[partial_length++] = '/';
+ strcpy(imp_lib + partial_length, TARGET_LIB);
+
+ dlhandle = dlopen(imp_lib, RTLD_LAZY);
+ if (!dlhandle)
+ {
+ strcpy(imp_lib + partial_length, TARGET_MERGED_LIB);
+
+ dlhandle = dlopen(imp_lib, RTLD_LAZY);
+ if (!dlhandle)
+ {
+ fprintf(stderr, "failed to open library '%s' or '%s' in '%s/'\n",
+ TARGET_LIB, TARGET_MERGED_LIB, install_path);
+ free(imp_lib);
+ return NULL;
+ }
+ }
+
+ pSym = (HookFunction *) dlsym( dlhandle, "libreofficekit_hook" );
+ if (!pSym)
+ {
+ fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
+ dlclose( dlhandle );
+ free( imp_lib );
+ return NULL;
+ }
+
+ free( imp_lib );
+ return pSym( install_path );
+}
+
+#endif // defined(__linux__) || defined(_AIX)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */