2013-03-05 07:16:36 -06:00
|
|
|
/* -*- 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef LINUX
|
|
|
|
|
2013-03-05 10:19:58 -06:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <osl/module.h>
|
2013-03-05 07:16:36 -06:00
|
|
|
#include <sal/types.h>
|
2013-03-05 10:19:58 -06:00
|
|
|
#include <liblibreoffice.hxx>
|
2013-03-05 07:16:36 -06:00
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#ifdef AIX
|
|
|
|
# include <sys/ldr.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TARGET_LIB SAL_MODULENAME( "sofficeapp" )
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
typedef LibLibreOffice *(HookFunction)(void);
|
|
|
|
};
|
|
|
|
|
2013-03-05 10:19:58 -06:00
|
|
|
SAL_DLLPUBLIC_EXPORT LibLibreOffice *lo_init( const char *install_path )
|
2013-03-05 07:16:36 -06:00
|
|
|
{
|
|
|
|
if( !install_path )
|
|
|
|
return NULL;
|
2013-05-13 18:11:22 -05:00
|
|
|
char* imp_lib = (char *) malloc( strlen (install_path) + sizeof( TARGET_LIB ) + 2 );
|
|
|
|
if(!imp_lib)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "failed to open library : not enough memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-03-05 07:16:36 -06:00
|
|
|
strcpy( imp_lib, install_path );
|
|
|
|
strcat( imp_lib, "/" );
|
|
|
|
strcat( imp_lib, TARGET_LIB );
|
|
|
|
void *dlhandle = dlopen( imp_lib, RTLD_LAZY );
|
|
|
|
if( !dlhandle )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "failed to open library '%s'\n", imp_lib );
|
2013-05-13 18:11:22 -05:00
|
|
|
free( imp_lib );
|
2013-03-05 07:16:36 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-05 10:19:58 -06:00
|
|
|
HookFunction *pSym = (HookFunction *) dlsym( dlhandle, "liblibreoffice_hook" );
|
2013-03-05 07:16:36 -06:00
|
|
|
if( !pSym ) {
|
|
|
|
fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
|
2013-05-13 18:11:22 -05:00
|
|
|
free( imp_lib );
|
2013-03-05 07:16:36 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-03-05 10:40:01 -06:00
|
|
|
|
|
|
|
free( imp_lib );
|
2013-03-05 07:16:36 -06:00
|
|
|
return pSym();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // LINUX - port me !
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|