1 /* -*- Mode: C++; tab-width: 6; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla XPCOM.
17 * The Initial Developer of the Original Code is
18 * Benjamin Smedberg <benjamin@smedbergs.us>
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
23 * Sergei Dolgov <sergei_d@fi.tartu.ee>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsGlueLinking.h"
40 #include "nsXPCOMGlue.h"
42 #include <kernel/image.h>
48 #define LEADING_UNDERSCORE
57 static DependentLib
*sTop
;
58 static image_id sXULLibHandle
;
61 AppendDependentLib(image_id libHandle
)
63 DependentLib
*d
= new DependentLib
;
68 d
->libHandle
= libHandle
;
74 ReadDependentCB(const char *aDependentLib
)
76 image_id libHandle
= load_add_on(aDependentLib
);
80 AppendDependentLib(libHandle
);
83 GetFrozenFunctionsFunc
84 XPCOMGlueLoad(const char *xpcomFile
)
86 char xpcomDir
[MAXPATHLEN
];
88 if (libpath
.SetTo(xpcomFile
, 0, true) == B_OK
) {
89 sprintf(xpcomDir
, libpath
.Path());
90 char *lastSlash
= strrchr(xpcomDir
, '/');
94 XPCOMGlueLoadDependentLibs(xpcomDir
, ReadDependentCB
);
96 snprintf(lastSlash
, MAXPATHLEN
- strlen(xpcomDir
), "/" XUL_DLL
);
98 sXULLibHandle
= load_add_on(xpcomDir
);
103 image_id libHandle
= nsnull
;
105 if (xpcomFile
[0] != '.' || xpcomFile
[1] != '\0') {
106 libHandle
= load_add_on(xpcomFile
);
108 AppendDependentLib(libHandle
);
112 GetFrozenFunctionsFunc sym
= 0;
115 result
= get_image_symbol(libHandle
,
116 LEADING_UNDERSCORE
"NS_GetFrozenFunctions", B_SYMBOL_TYPE_TEXT
, (void **)sym
);
118 if (!sym
|| B_OK
!= result
)
128 unload_add_on(sTop
->libHandle
);
130 DependentLib
*temp
= sTop
;
137 unload_add_on(sXULLibHandle
);
138 sXULLibHandle
= nsnull
;
143 XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad
*symbols
)
148 while (symbols
->functionName
) {
150 snprintf(buffer
, sizeof(buffer
),
151 LEADING_UNDERSCORE
"%s", symbols
->functionName
);
153 *symbols
->function
= 0;
155 result
= get_image_symbol(sXULLibHandle
, buffer
, B_SYMBOL_TYPE_TEXT
, (void **)*symbols
->function
);
156 if (!*symbols
->function
|| B_OK
!= result
)
157 rv
= NS_ERROR_LOSS_OF_SIGNIFICANT_DATA
;