xref: /aoo41x/main/sal/osl/all/loadmodulerelative.cxx (revision 80036c20)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sal.hxx"
26 
27 #include "sal/config.h"
28 
29 #include <cstddef>
30 
31 #include "osl/diagnose.h"
32 #include "osl/module.h"
33 #include "osl/module.hxx"
34 #include "osl/thread.h"
35 #include "rtl/malformeduriexception.hxx"
36 #include "rtl/uri.hxx"
37 #include "rtl/ustring.h"
38 #include "rtl/ustring.hxx"
39 #include "sal/types.h"
40 
41 extern "C" {
42 
osl_loadModuleRelative(oslGenericFunction const baseModule,rtl_uString * const relativePath,sal_Int32 const mode)43 oslModule SAL_CALL osl_loadModuleRelative(
44     oslGenericFunction const baseModule, rtl_uString * const relativePath,
45     sal_Int32 const mode)
46 {
47     ::rtl::OUString base;
48     if (!::osl::Module::getUrlFromAddress(baseModule, base)) {
49         OSL_TRACE("osl::Module::getUrlFromAddress failed");
50         return NULL;
51     }
52     ::rtl::OUString abs;
53     try {
54         abs = ::rtl::Uri::convertRelToAbs(base, relativePath);
55     } catch (::rtl::MalformedUriException & e) {
56         (void) e; // avoid warnings
57         OSL_TRACE(
58             "rtl::MalformedUriException <%s>",
59             rtl::OUStringToOString(e.getMessage(), osl_getThreadTextEncoding()).
60                 getStr());
61             //TODO: let some OSL_TRACE variant take care of text conversion?
62         return NULL;
63     }
64     return ::osl_loadModule(abs.pData, mode);
65 }
66 
osl_loadAsciiModuleRelative(oslGenericFunction const baseModule,const sal_Char * pRelativePathName,sal_Int32 const nRtldMode)67 oslModule SAL_CALL osl_loadAsciiModuleRelative(
68     oslGenericFunction const baseModule, const sal_Char* pRelativePathName,
69     sal_Int32 const nRtldMode)
70 {
71 	rtl_uString* pUniName = NULL;
72 	rtl_uString_newFromAscii( &pUniName, pRelativePathName );
73 	oslModule aModule = osl_loadModuleRelative( baseModule, pUniName, nRtldMode );
74 	rtl_uString_release( pUniName );
75 	return aModule;
76 }
77 
78 }
79