Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / xpcom / glue / standalone / nsGlueLinkingBeOS.cpp
blobd5032457ffb3e89b8b17280cb94d3e5941c98eed
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
13 * License.
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.
22 * Contributor(s):
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>
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <Entry.h>
46 #include <Path.h>
48 #define LEADING_UNDERSCORE
51 struct DependentLib
53 image_id libHandle;
54 DependentLib *next;
57 static DependentLib *sTop;
58 static image_id sXULLibHandle;
60 static void
61 AppendDependentLib(image_id libHandle)
63 DependentLib *d = new DependentLib;
64 if (!d)
65 return;
67 d->next = sTop;
68 d->libHandle = libHandle;
70 sTop = d;
73 static void
74 ReadDependentCB(const char *aDependentLib)
76 image_id libHandle = load_add_on(aDependentLib);
77 if (!libHandle)
78 return;
80 AppendDependentLib(libHandle);
83 GetFrozenFunctionsFunc
84 XPCOMGlueLoad(const char *xpcomFile)
86 char xpcomDir[MAXPATHLEN];
87 BPath libpath;
88 if (libpath.SetTo(xpcomFile, 0, true) == B_OK) {
89 sprintf(xpcomDir, libpath.Path());
90 char *lastSlash = strrchr(xpcomDir, '/');
91 if (lastSlash) {
92 *lastSlash = '\0';
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);
107 if (libHandle) {
108 AppendDependentLib(libHandle);
112 GetFrozenFunctionsFunc sym = 0;
113 status_t result;
115 result = get_image_symbol(libHandle,
116 LEADING_UNDERSCORE "NS_GetFrozenFunctions", B_SYMBOL_TYPE_TEXT, (void **)sym);
118 if (!sym || B_OK != result)
119 XPCOMGlueUnload();
121 return sym;
124 void
125 XPCOMGlueUnload()
127 while (sTop) {
128 unload_add_on(sTop->libHandle);
130 DependentLib *temp = sTop;
131 sTop = sTop->next;
133 delete temp;
136 if (sXULLibHandle) {
137 unload_add_on(sXULLibHandle);
138 sXULLibHandle = nsnull;
142 nsresult
143 XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad *symbols)
146 nsresult rv = NS_OK;
148 while (symbols->functionName) {
149 char buffer[512];
150 snprintf(buffer, sizeof(buffer),
151 LEADING_UNDERSCORE "%s", symbols->functionName);
153 *symbols->function = 0;
154 status_t result;
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;
159 ++symbols;
161 return rv;