diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2018-07-06 17:41:58 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2018-07-09 10:14:49 +0200 |
commit | 2872653997b614cc788c8a632a4d5ccb63c4670d (patch) | |
tree | 3f0fe9fb0b02beca5758732b8fc90ae93b203f29 | |
parent | a8ebc12eabe2e49e7d1564027c7128898279944e (diff) |
lok: export preinit helper, and share code variously.
Change-Id: I09f2992c4ba45ce91190a9f61dd0fedd0eb8a581
Reviewed-on: https://gerrit.libreoffice.org/57145
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKitInit.h | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitInit.h b/include/LibreOfficeKit/LibreOfficeKitInit.h index ce5054ac91c4..103c11be926c 100644 --- a/include/LibreOfficeKit/LibreOfficeKitInit.h +++ b/include/LibreOfficeKit/LibreOfficeKitInit.h @@ -17,6 +17,12 @@ extern "C" { #endif +#if defined __GNUC__ || defined __clang__ +# define LOK_TOLERATE_UNUSED __attribute__((used)) +#else +# define LOK_TOLERATE_UNUSED +#endif + #if defined(__linux__) || defined (__FreeBSD_kernel__) || defined(_AIX) ||\ defined(_WIN32) || defined(__APPLE__) || defined (__NetBSD__) ||\ defined (__sun) || defined(__OpenBSD__) @@ -294,15 +300,41 @@ static LibreOfficeKit *lok_init_2( const char *install_path, const char *user_p #endif } -static -#if defined __GNUC__ || defined __clang__ -__attribute__((used)) -#endif +static LOK_TOLERATE_UNUSED LibreOfficeKit *lok_init( const char *install_path ) { return lok_init_2( install_path, NULL ); } +#if !defined(IOS) +static LOK_TOLERATE_UNUSED +int lok_preinit( const char *install_path, const char *user_profile_url ) +{ + void *dlhandle; + char *imp_lib; + LokHookPreInit *pSym; + + dlhandle = lok_dlopen(install_path, &imp_lib); + if (!dlhandle) + return -1; + + pSym = (LokHookPreInit *) lok_dlsym(dlhandle, "lok_preinit"); + if (!pSym) + { + fprintf( stderr, "failed to find pre-init hook in library '%s'\n", imp_lib ); + lok_dlclose( dlhandle ); + free( imp_lib ); + return -1; + } + + free( imp_lib ); + + // dlhandle is "leaked" + // coverity[leaked_storage] + return pSym( install_path, user_profile_url ); +} +#endif + #undef SEPARATOR // It is used at least in enum class MenuItemType #endif // defined(__linux__) || defined (__FreeBSD_kernel__) || defined(_AIX) || defined(_WIN32) || defined(__APPLE__) |