diff options
author | Jan Holesovsky <kendy@collabora.com> | 2014-07-16 19:36:53 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2014-07-16 19:40:20 +0200 |
commit | 73b10c81c90dc5908e48c72ee97478c8a8fbdc62 (patch) | |
tree | e0f481593efbeed22cb5fbcd80ebb901b533ea93 /libreofficekit/source | |
parent | 98fb5f98d84474103a04cbad824febecb25407c2 (diff) |
LibreOfficeKit: Check for libmerged too.
And avoid some strcat's when at it.
Change-Id: I0c70ee2a1abf0c9e2914f756b06bedc3a16df19b
Diffstat (limited to 'libreofficekit/source')
-rw-r--r-- | libreofficekit/source/shim.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/libreofficekit/source/shim.c b/libreofficekit/source/shim.c index 6a3f9a78cdfa..ac272e8d8c04 100644 --- a/libreofficekit/source/shim.c +++ b/libreofficekit/source/shim.c @@ -10,9 +10,9 @@ #ifdef LINUX #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <osl/module.h> #include <sal/types.h> #include <LibreOfficeKit/LibreOfficeKit.h> @@ -21,37 +21,52 @@ # include <sys/ldr.h> #endif -#define TARGET_LIB SAL_MODULENAME( "sofficeapp" ) +#define TARGET_LIB "lib" "sofficeapp" ".so" +#define TARGET_MERGED_LIB "lib" "libmergedlo" ".so" typedef LibreOfficeKit *(HookFunction)( const char *install_path); SAL_DLLPUBLIC_EXPORT LibreOfficeKit *lok_init( const char *install_path ) { char *imp_lib; + size_t partial_length; void *dlhandle; HookFunction *pSym; - if( !install_path ) + if (!install_path) return NULL; - if( !( imp_lib = (char *) malloc( strlen (install_path) + sizeof( TARGET_LIB ) + 2 ) ) ) + + // 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 ); - strcat( imp_lib, "/" ); - strcat( imp_lib, TARGET_LIB ); + strcpy(imp_lib, install_path); + + imp_lib[partial_length++] = '/'; + strcpy(imp_lib + partial_length, TARGET_LIB); - if( !( dlhandle = dlopen( imp_lib, RTLD_LAZY ) ) ) + dlhandle = dlopen(imp_lib, RTLD_LAZY); + if (!dlhandle) { - fprintf( stderr, "failed to open library '%s'\n", imp_lib ); - free( imp_lib ); - return NULL; + 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 ) { + if (!pSym) + { fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib ); dlclose( dlhandle ); free( imp_lib ); |