1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "GLLibraryLoader.h"
13 GLLibraryLoader::OpenLibrary(const char *library
)
16 lspec
.type
= PR_LibSpec_Pathname
;
17 lspec
.value
.pathname
= library
;
19 mLibrary
= PR_LoadLibraryWithFlags(lspec
, PR_LD_LAZY
| PR_LD_LOCAL
);
27 GLLibraryLoader::LoadSymbols(SymLoadStruct
*firstStruct
,
32 return LoadSymbols(mLibrary
,
34 tryplatform
? mLookupFunc
: nullptr,
40 GLLibraryLoader::LookupSymbol(PRLibrary
*lib
,
42 PlatformLookupFunction lookupFunction
)
46 // try finding it in the library directly, if we have one
48 res
= PR_FindFunctionSymbol(lib
, sym
);
51 // then try looking it up via the lookup symbol
52 if (!res
&& lookupFunction
) {
53 res
= lookupFunction(sym
);
56 // finally just try finding it in the process
58 PRLibrary
*leakedLibRef
;
59 res
= PR_FindFunctionSymbolAndLibrary(sym
, &leakedLibRef
);
66 GLLibraryLoader::LoadSymbols(PRLibrary
*lib
,
67 SymLoadStruct
*firstStruct
,
68 PlatformLookupFunction lookupFunction
,
72 char sbuf
[MAX_SYMBOL_LENGTH
* 2];
75 SymLoadStruct
*ss
= firstStruct
;
76 while (ss
->symPointer
) {
79 for (int i
= 0; i
< MAX_SYMBOL_NAMES
; i
++) {
80 if (ss
->symNames
[i
] == nullptr)
83 const char *s
= ss
->symNames
[i
];
84 if (prefix
&& *prefix
!= 0) {
86 strcat(sbuf
, ss
->symNames
[i
]);
90 PRFuncPtr p
= LookupSymbol(lib
, s
, lookupFunction
);
97 if (*ss
->symPointer
== 0) {
99 printf_stderr("Can't find symbol '%s'.\n", ss
->symNames
[0]);
107 return failCount
== 0 ? true : false;
111 } /* namespace mozilla */