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>
20 * Portions created by the Initial Developer are Copyright (C) 2005
21 * the Initial Developer. All Rights Reserved.
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"
43 #define INCL_DOSERRORS
54 static DependentLib
*sTop
;
55 HMODULE sXULLibrary
= NULLHANDLE
;
58 AppendDependentLib(HMODULE libHandle
)
60 DependentLib
*d
= new DependentLib
;
65 d
->libHandle
= libHandle
;
71 ReadDependentCB(const char *aDependentLib
)
73 CHAR pszError
[_MAX_PATH
];
74 ULONG ulrc
= NO_ERROR
;
77 ulrc
= DosLoadModule(pszError
, _MAX_PATH
, aDependentLib
, &h
);
82 AppendDependentLib(h
);
85 // like strpbrk but finds the *last* char, not the first
87 ns_strrpbrk(char *string
, const char *strCharSet
)
90 for (; *string
; ++string
) {
91 for (const char *search
= strCharSet
; *search
; ++search
) {
92 if (*search
== *string
) {
94 // Since we're looking for the last char, we save "found"
95 // until we're at the end of the string.
103 GetFrozenFunctionsFunc
104 XPCOMGlueLoad(const char *xpcomFile
)
106 CHAR pszError
[_MAX_PATH
];
107 ULONG ulrc
= NO_ERROR
;
110 if (xpcomFile
[0] == '.' && xpcomFile
[1] == '\0') {
111 xpcomFile
= XPCOM_DLL
;
114 char xpcomDir
[MAXPATHLEN
];
116 _fullpath(xpcomDir
, xpcomFile
, sizeof(xpcomDir
));
117 char *lastSlash
= ns_strrpbrk(xpcomDir
, "/\\");
121 XPCOMGlueLoadDependentLibs(xpcomDir
, ReadDependentCB
);
123 snprintf(lastSlash
, MAXPATHLEN
- strlen(xpcomDir
), "\\" XUL_DLL
);
125 DosLoadModule(pszError
, _MAX_PATH
, xpcomDir
, &sXULLibrary
);
129 ulrc
= DosLoadModule(pszError
, _MAX_PATH
, xpcomFile
, &h
);
131 if (ulrc
!= NO_ERROR
)
134 AppendDependentLib(h
);
136 GetFrozenFunctionsFunc sym
;
138 ulrc
= DosQueryProcAddr(h
, 0, "_NS_GetFrozenFunctions", (PFN
*)&sym
);
140 if (ulrc
!= NO_ERROR
)
150 DosFreeModule(sTop
->libHandle
);
152 DependentLib
*temp
= sTop
;
159 DosFreeModule(sXULLibrary
);
160 sXULLibrary
= nsnull
;
165 XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad
*symbols
)
167 ULONG ulrc
= NO_ERROR
;
170 return NS_ERROR_NOT_INITIALIZED
;
173 while (symbols
->functionName
) {
175 snprintf(buffer
, sizeof(buffer
), "_%s", symbols
->functionName
);
176 ulrc
= DosQueryProcAddr(sXULLibrary
, 0, buffer
, (PFN
*)symbols
->function
);
178 if (ulrc
!= NO_ERROR
)
179 rv
= NS_ERROR_LOSS_OF_SIGNIFICANT_DATA
;