update credits
[LibreOffice.git] / desktop / source / lib / shim.cxx
blob8c47dc42ad1ee5a257056141fea46bc4676f1ae4
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifdef LINUX
12 #include <stdio.h>
13 #include <string.h>
15 #include <osl/module.h>
16 #include <sal/types.h>
17 #include <liblibreoffice.hxx>
19 #include <dlfcn.h>
20 #ifdef AIX
21 # include <sys/ldr.h>
22 #endif
24 #define TARGET_LIB SAL_MODULENAME( "sofficeapp" )
26 extern "C" {
27 typedef LibLibreOffice *(HookFunction)(void);
30 SAL_DLLPUBLIC_EXPORT LibLibreOffice *lo_init( const char *install_path )
32 if( !install_path )
33 return NULL;
34 char* imp_lib = (char *) malloc( strlen (install_path) + sizeof( TARGET_LIB ) + 2 );
35 if(!imp_lib)
37 fprintf( stderr, "failed to open library : not enough memory\n");
38 return NULL;
40 strcpy( imp_lib, install_path );
41 strcat( imp_lib, "/" );
42 strcat( imp_lib, TARGET_LIB );
43 void *dlhandle = dlopen( imp_lib, RTLD_LAZY );
44 if( !dlhandle )
46 fprintf( stderr, "failed to open library '%s'\n", imp_lib );
47 free( imp_lib );
48 return NULL;
51 HookFunction *pSym = (HookFunction *) dlsym( dlhandle, "liblibreoffice_hook" );
52 if( !pSym ) {
53 fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
54 free( imp_lib );
55 return NULL;
58 free( imp_lib );
59 return pSym();
62 #endif // LINUX - port me !
64 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */