Blame SOURCES/0096-lok-namespace-and-re-work-various-types-helper-funct.patch

135360
From c8a7b2b66db5025526a0dba1b0d33dcf1b93f985 Mon Sep 17 00:00:00 2001
135360
From: Michael Meeks <michael.meeks@collabora.com>
135360
Date: Tue, 18 Aug 2015 12:09:08 +0100
135360
Subject: [PATCH 096/398] lok: namespace and re-work various types & helper
135360
 functions.
135360
135360
Change-Id: I36e2a01822883251f9556fcde0e0a9830356ac98
135360
Reviewed-on: https://gerrit.libreoffice.org/17833
135360
Tested-by: Jenkins <ci@libreoffice.org>
135360
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
135360
Tested-by: Michael Meeks <michael.meeks@collabora.com>
135360
(cherry picked from commit a5d5ce5dfa0f0cdd048192d60c70da575a6f1735)
135360
---
135360
 include/LibreOfficeKit/LibreOfficeKitInit.h | 60 ++++++++++++++++++-----------
135360
 1 file changed, 37 insertions(+), 23 deletions(-)
135360
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKitInit.h b/include/LibreOfficeKit/LibreOfficeKitInit.h
135360
index f1966c764605..c2f342661e31 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKitInit.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKitInit.h
135360
@@ -40,7 +40,7 @@ extern "C"
135360
     #endif
135360
     #define SEPARATOR         '/'
135360
 
135360
-    void *_dlopen(const char *pFN)
135360
+    void *lok_loadlib(const char *pFN)
135360
     {
135360
         return dlopen(pFN, RTLD_LAZY
135360
 #if defined __clang__ && defined __linux__ \
135360
@@ -52,17 +52,17 @@ extern "C"
135360
                       );
135360
     }
135360
 
135360
-    char *_dlerror(void)
135360
+    char *lok_dlerror(void)
135360
     {
135360
         return dlerror();
135360
     }
135360
 
135360
-    void *_dlsym(void *Hnd, const char *pName)
135360
+    void *lok_dlsym(void *Hnd, const char *pName)
135360
     {
135360
         return dlsym(Hnd, pName);
135360
     }
135360
 
135360
-    int _dlclose(void *Hnd)
135360
+    int lok_dlclose(void *Hnd)
135360
     {
135360
         return dlclose(Hnd);
135360
     }
135360
@@ -80,24 +80,24 @@ extern "C"
135360
     #define SEPARATOR         '\\'
135360
     #define UNOPATH           "\\..\\URE\\bin"
135360
 
135360
-    void *_dlopen(const char *pFN)
135360
+    void *lok_loadlib(const char *pFN)
135360
     {
135360
         return (void *) LoadLibrary(pFN);
135360
     }
135360
 
135360
-    char *_dlerror(void)
135360
+    char *lok_dlerror(void)
135360
     {
135360
         LPSTR buf = NULL;
135360
         FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, reinterpret_cast<LPSTR>(&buf), 0, NULL);
135360
         return buf;
135360
     }
135360
 
135360
-    void *_dlsym(void *Hnd, const char *pName)
135360
+    void *lok_dlsym(void *Hnd, const char *pName)
135360
     {
135360
         return GetProcAddress((HINSTANCE) Hnd, pName);
135360
     }
135360
 
135360
-    int _dlclose(void *Hnd)
135360
+    int lok_dlclose(void *Hnd)
135360
     {
135360
         return FreeLibrary((HINSTANCE) Hnd);
135360
     }
135360
@@ -139,16 +139,12 @@ extern "C"
135360
     }
135360
 #endif
135360
 
135360
-typedef LibreOfficeKit *(HookFunction)( const char *install_path);
135360
-
135360
-typedef LibreOfficeKit *(HookFunction2)( const char *install_path, const char *user_profile_path );
135360
-
135360
-static LibreOfficeKit *lok_init_2( const char *install_path,  const char *user_profile_path )
135360
+static void *lok_dlopen( const char *install_path, char ** _imp_lib )
135360
 {
135360
     char *imp_lib;
135360
     void *dlhandle;
135360
-    HookFunction *pSym;
135360
-    HookFunction2 *pSym2;
135360
+
135360
+    *_imp_lib = NULL;
135360
 
135360
 #if !(defined(__APPLE__) && defined(__arm__))
135360
     size_t partial_length;
135360
@@ -172,7 +168,7 @@ static LibreOfficeKit *lok_init_2( const char *install_path,  const char *user_p
135360
     imp_lib[partial_length++] = SEPARATOR;
135360
     strcpy(imp_lib + partial_length, TARGET_LIB);
135360
 
135360
-    dlhandle = _dlopen(imp_lib);
135360
+    dlhandle = lok_loadlib(imp_lib);
135360
     if (!dlhandle)
135360
     {
135360
         // If TARGET_LIB exists, and likely is a real library (not a
135360
@@ -183,18 +179,18 @@ static LibreOfficeKit *lok_init_2( const char *install_path,  const char *user_p
135360
         if (stat(imp_lib, &st) == 0 && st.st_size > 100)
135360
         {
135360
             fprintf(stderr, "failed to open library '%s': %s\n",
135360
-                    imp_lib, _dlerror());
135360
+                    imp_lib, lok_dlerror());
135360
             free(imp_lib);
135360
             return NULL;
135360
         }
135360
 
135360
         strcpy(imp_lib + partial_length, TARGET_MERGED_LIB);
135360
 
135360
-        dlhandle = _dlopen(imp_lib);
135360
+        dlhandle = lok_loadlib(imp_lib);
135360
         if (!dlhandle)
135360
         {
135360
             fprintf(stderr, "failed to open library '%s': %s\n",
135360
-                    imp_lib, _dlerror());
135360
+                    imp_lib, lok_dlerror());
135360
             free(imp_lib);
135360
             return NULL;
135360
         }
135360
@@ -203,23 +199,41 @@ static LibreOfficeKit *lok_init_2( const char *install_path,  const char *user_p
135360
     imp_lib = strdup("the app executable");
135360
     dlhandle = RTLD_MAIN_ONLY;
135360
 #endif
135360
+    *_imp_lib = imp_lib;
135360
+    return dlhandle;
135360
+}
135360
+
135360
+typedef LibreOfficeKit *(LokHookFunction)( const char *install_path);
135360
+
135360
+typedef LibreOfficeKit *(LokHookFunction2)( const char *install_path, const char *user_profile_path );
135360
+
135360
+typedef int             (LokHookPreInit)  ( const char *install_path, const char *user_profile_path );
135360
+
135360
+static LibreOfficeKit *lok_init_2( const char *install_path,  const char *user_profile_path )
135360
+{
135360
+    char *imp_lib;
135360
+    void *dlhandle;
135360
+    LokHookFunction *pSym;
135360
+    LokHookFunction2 *pSym2;
135360
+
135360
+    dlhandle = lok_dlopen(install_path, &imp_lib);
135360
 
135360
-    pSym2 = (HookFunction2 *) _dlsym( dlhandle, "libreofficekit_hook_2" );
135360
+    pSym2 = (LokHookFunction2 *) lok_dlsym(dlhandle, "libreofficekit_hook_2");
135360
     if (!pSym2)
135360
     {
135360
         if (user_profile_path != NULL)
135360
         {
135360
             fprintf( stderr, "the LibreOffice version in '%s' does not support passing a user profile to the hook function\n",
135360
                      imp_lib );
135360
-            _dlclose( dlhandle );
135360
+            lok_dlclose( dlhandle );
135360
             free( imp_lib );
135360
             return NULL;
135360
         }
135360
-        pSym = (HookFunction *) _dlsym( dlhandle, "libreofficekit_hook" );
135360
+        pSym = (LokHookFunction *) lok_dlsym( dlhandle, "libreofficekit_hook" );
135360
         if (!pSym)
135360
         {
135360
             fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
135360
-            _dlclose( dlhandle );
135360
+            lok_dlclose( dlhandle );
135360
             free( imp_lib );
135360
             return NULL;
135360
         }
135360
-- 
135360
2.12.0
135360