1a06f7ccaSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3a06f7ccaSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4a06f7ccaSAndrew Rist * or more contributor license agreements. See the NOTICE file 5a06f7ccaSAndrew Rist * distributed with this work for additional information 6a06f7ccaSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7a06f7ccaSAndrew Rist * to you under the Apache License, Version 2.0 (the 8a06f7ccaSAndrew Rist * "License"); you may not use this file except in compliance 9a06f7ccaSAndrew Rist * with the License. You may obtain a copy of the License at 10a06f7ccaSAndrew Rist * 11a06f7ccaSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12a06f7ccaSAndrew Rist * 13a06f7ccaSAndrew Rist * Unless required by applicable law or agreed to in writing, 14a06f7ccaSAndrew Rist * software distributed under the License is distributed on an 15a06f7ccaSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16a06f7ccaSAndrew Rist * KIND, either express or implied. See the License for the 17a06f7ccaSAndrew Rist * specific language governing permissions and limitations 18a06f7ccaSAndrew Rist * under the License. 19a06f7ccaSAndrew Rist * 20a06f7ccaSAndrew Rist *************************************************************/ 21a06f7ccaSAndrew Rist 22a06f7ccaSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <rtl/string.h> 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <stdlib.h> 27cdf0e10cSrcweir #include <string.h> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #ifdef LINUX 30cdf0e10cSrcweir # ifndef __USE_GNU 31cdf0e10cSrcweir # define __USE_GNU 32cdf0e10cSrcweir # endif 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir #include <dlfcn.h> 35cdf0e10cSrcweir 36*58c70741SJim Jagielski SAL_DLLPUBLIC_EXPORT void initpyuno () 37cdf0e10cSrcweir { 38cdf0e10cSrcweir Dl_info dl_info; 39cdf0e10cSrcweir void (*func)(void); 40cdf0e10cSrcweir 41cdf0e10cSrcweir if (dladdr((void*)&initpyuno, &dl_info) != 0) { 42cdf0e10cSrcweir void* h = 0; 43cdf0e10cSrcweir size_t len = strrchr(dl_info.dli_fname, '/') - dl_info.dli_fname + 1; 44cdf0e10cSrcweir char* libname = malloc(len + RTL_CONSTASCII_LENGTH( SAL_DLLPREFIX "pyuno" SAL_DLLEXTENSION ) + 1); 45cdf0e10cSrcweir strncpy(libname, dl_info.dli_fname, len); 46cdf0e10cSrcweir strcpy(libname + (len), SAL_DLLPREFIX "pyuno" SAL_DLLEXTENSION); 47cdf0e10cSrcweir 48cdf0e10cSrcweir h = dlopen (libname, RTLD_NOW | RTLD_GLOBAL); 49cdf0e10cSrcweir free(libname); 50cdf0e10cSrcweir if( h ) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir func = (void (*)())dlsym (h, "initpyuno"); 53cdf0e10cSrcweir (func) (); 54cdf0e10cSrcweir } 55cdf0e10cSrcweir } 56cdf0e10cSrcweir } 57