LCOV - code coverage report
Current view: top level - include/LibreOfficeKit - LibreOfficeKitInit.h (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 27 0.0 %
Date: 2014-11-03 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  */
       9             : 
      10             : #ifndef INCLUDED_DESKTOP_INC_LIBREOFFICEKIT_INIT_H
      11             : #define INCLUDED_DESKTOP_INC_LIBREOFFICEKIT_INIT_H
      12             : 
      13             : #include "LibreOfficeKit.h"
      14             : 
      15             : #ifdef __cplusplus
      16             : extern "C"
      17             : {
      18             : #endif
      19             : 
      20             : #if defined(__linux__) || defined (__FreeBSD_kernel__) || defined(_AIX)
      21             : 
      22             : #include <stdio.h>
      23             : #include <stdlib.h>
      24             : #include <string.h>
      25             : 
      26             : #include <dlfcn.h>
      27             : #ifdef  _AIX
      28             : #  include <sys/ldr.h>
      29             : #endif
      30             : 
      31             : #define TARGET_LIB        "lib" "sofficeapp" ".so"
      32             : #define TARGET_MERGED_LIB "lib" "mergedlo" ".so"
      33             : 
      34             : typedef LibreOfficeKit *(HookFunction)( const char *install_path);
      35             : 
      36           0 : static LibreOfficeKit *lok_init( const char *install_path )
      37             : {
      38             :     char *imp_lib;
      39             :     size_t partial_length;
      40             :     void *dlhandle;
      41             :     HookFunction *pSym;
      42             : 
      43           0 :     if (!install_path)
      44           0 :         return NULL;
      45             : 
      46             :     // allocate large enough buffer
      47           0 :     partial_length = strlen(install_path);
      48           0 :     imp_lib = (char *) malloc(partial_length + sizeof(TARGET_LIB) + sizeof(TARGET_MERGED_LIB) + 2);
      49           0 :     if (!imp_lib)
      50             :     {
      51           0 :         fprintf( stderr, "failed to open library : not enough memory\n");
      52           0 :         return NULL;
      53             :     }
      54             : 
      55           0 :     strcpy(imp_lib, install_path);
      56             : 
      57           0 :     imp_lib[partial_length++] = '/';
      58           0 :     strcpy(imp_lib + partial_length, TARGET_LIB);
      59             : 
      60           0 :     dlhandle = dlopen(imp_lib, RTLD_LAZY);
      61           0 :     if (!dlhandle)
      62             :     {
      63           0 :         strcpy(imp_lib + partial_length, TARGET_MERGED_LIB);
      64             : 
      65           0 :         dlhandle = dlopen(imp_lib, RTLD_LAZY);
      66           0 :         if (!dlhandle)
      67             :         {
      68             :             fprintf(stderr, "failed to open library '%s' or '%s' in '%s/'\n",
      69           0 :                     TARGET_LIB, TARGET_MERGED_LIB, install_path);
      70           0 :             free(imp_lib);
      71           0 :             return NULL;
      72             :         }
      73             :     }
      74             : 
      75           0 :     pSym = (HookFunction *) dlsym( dlhandle, "libreofficekit_hook" );
      76           0 :     if (!pSym)
      77             :     {
      78           0 :         fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
      79           0 :         dlclose( dlhandle );
      80           0 :         free( imp_lib );
      81           0 :         return NULL;
      82             :     }
      83             : 
      84           0 :     free( imp_lib );
      85           0 :     return pSym( install_path );
      86             : }
      87             : 
      88             : #endif // defined(__linux__) || defined(_AIX)
      89             : 
      90             : #ifdef __cplusplus
      91             : }
      92             : #endif
      93             : 
      94             : #endif
      95             : 
      96             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10