merge the formfield patch from ooo-build
[ooovba.git] / applied_patches / 0074-nsplugin-path.diff
blobda1d95b68bc80ac5c2b6d47abd907646e7c07d20
1 --- extensions/source/nsplugin/source/so_env.cxx.old 2009-04-02 10:51:19.000000000 +0000
2 +++ extensions/source/nsplugin/source/so_env.cxx 2009-04-06 16:41:44.000000000 +0000
3 @@ -34,6 +34,7 @@
4 #ifdef UNIX
5 #include <sys/types.h>
6 #include <strings.h>
7 +#include <dlfcn.h>
8 #include <stdarg.h>
9 // For vsnprintf()
10 #define NSP_vsnprintf vsnprintf
11 @@ -122,6 +123,96 @@ restoreUTF8(char *pPath)
12 return 0;
15 +#ifdef UNIX
16 +extern int nspluginOOoModuleHook (void** aResult);
17 +int nspluginOOoModuleHook (void** aResult)
19 + void *dl_handle;
20 + void *thisp;
22 + dl_handle = dlopen(NULL, RTLD_NOW);
23 + if (!dl_handle)
24 + {
25 + fprintf (stderr, "Can't open myself '%s'\n", dlerror());
26 + return 1;
27 + }
29 + Dl_info dl_info = { 0, };
30 + if(!dladdr((void *)nspluginOOoModuleHook, &dl_info))
31 + {
32 + fprintf (stderr, "Can't find my own address '%s'\n", dlerror());
33 + return 1;
34 + }
36 + if (!dl_info.dli_fname)
37 + {
38 + fprintf (stderr, "Can't find my own file name\n");
39 + return 1;
40 + }
42 + char cwdstr[NPP_PATH_MAX];
43 + if (!getcwd (cwdstr, sizeof(cwdstr)))
44 + {
45 + fprintf (stderr, "Can't get cwd\n");
46 + return 1;
47 + }
49 + char libFileName[NPP_PATH_MAX];
51 + if (dl_info.dli_fname[0] != '/')
52 + {
53 + if ((strlen(cwdstr) + 1 + strlen(dl_info.dli_fname)) >= NPP_PATH_MAX)
54 + {
55 + fprintf (stderr, "Plugin path too long\n");
56 + return 1;
57 + }
58 + strcpy (libFileName, cwdstr);
59 + strcat (libFileName, "/");
60 + strcat (libFileName, dl_info.dli_fname);
61 + }
62 + else
63 + {
64 + if (strlen(dl_info.dli_fname) >= NPP_PATH_MAX)
65 + {
66 + fprintf (stderr, "Plugin path too long\n");
67 + return 1;
68 + }
69 + strcpy (libFileName, dl_info.dli_fname);
70 + }
72 + char *clobber;
73 + static char realFileName[NPP_PATH_MAX] = {0};
74 +# define SEARCH_SUFFIX "/program/libnpsoplug"
76 + if (!(clobber = strstr (libFileName, SEARCH_SUFFIX)))
77 + {
78 + ssize_t len = readlink(libFileName, realFileName, NPP_PATH_MAX-1);
79 + if (len == -1)
80 + {
81 + fprintf (stderr, "Couldn't read link '%s'\n", libFileName);
82 + return 1;
83 + }
84 + realFileName[len] = '\0';
85 + if (!(clobber = strstr (realFileName, SEARCH_SUFFIX)))
86 + {
87 + fprintf (stderr, "Couldn't find suffix in '%s'\n", realFileName);
88 + return 1;
89 + }
90 + *clobber = '\0';
91 + }
92 + else
93 + {
94 + *clobber = '\0';
95 + strcpy (realFileName, libFileName);
96 + }
97 + *aResult = realFileName;
99 + fprintf (stderr, "OpenOffice path is '%s'\n", realFileName);
101 + return 0;
103 +#endif
105 // *aResult points the static string holding "/opt/staroffice8"
106 int findReadSversion(void** aResult, int /*bWnt*/, const char* /*tag*/, const char* /*entry*/)
108 @@ -134,9 +225,22 @@ int findReadSversion(void** aResult, int
109 // Filename of lnk file, eg. "soffice"
110 char lnkFileName[NPP_PATH_MAX] = {0};
111 char* pTempZero = NULL;
113 + /* try to fetch a 'self' pointer */
114 + if (!nspluginOOoModuleHook (aResult))
115 + return 0;
117 + /* .. now in $HOME */
118 sprintf(lnkFileName, "%s/.mozilla/plugins/libnpsoplugin%s", getenv("HOME"), SAL_DLLEXTENSION);
119 - if ((0 > readlink(lnkFileName, realFileName, NPP_PATH_MAX)) ||
120 - (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin" SAL_DLLEXTENSION))))
121 + ssize_t len = readlink(lnkFileName, realFileName, NPP_PATH_MAX-1);
122 + if (-1 == len)
124 + *realFileName = 0;
125 + return -1;
127 + realFileName[len] = '\0';
129 + if (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin" SAL_DLLEXTENSION)))
131 *realFileName = 0;
132 return -1;