1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "nsCUPSShim.h"
10 #include "mozilla/ArrayUtils.h"
13 #ifdef CUPS_SHIM_RUNTIME_LINK
15 // TODO: This is currently pointless as we always use the compile-time linked
16 // version of CUPS, but in the future this may become a configure option.
17 // We also cannot use NSPR's library suffix support, since that cannot handle
18 // version number suffixes.
20 static const char gCUPSLibraryName
[] = "libcups.2.dylib";
22 static const char gCUPSLibraryName
[] = "libcups.so.2";
25 template <typename FuncT
>
26 static bool LoadCupsFunc(PRLibrary
*& lib
, FuncT
*& dest
,
27 const char* const name
) {
28 dest
= (FuncT
*)PR_FindSymbol(lib
, name
);
29 if (MOZ_UNLIKELY(!dest
)) {
31 nsAutoCString
msg(name
);
32 msg
.AppendLiteral(" not found in CUPS library");
33 NS_WARNING(msg
.get());
36 // With TSan, we cannot unload libcups once we have loaded it because
37 // TSan does not support unloading libraries that are matched from its
38 // suppression list. Hence we just keep the library loaded in TSan builds.
39 PR_UnloadLibrary(lib
);
47 nsCUPSShim::nsCUPSShim() {
48 mCupsLib
= PR_LoadLibrary(gCUPSLibraryName
);
53 // This is a macro so that it could also load from libcups if we are
54 // configured to use it as a compile-time dependency.
55 # define CUPS_SHIM_LOAD(NAME) \
56 if (!LoadCupsFunc(mCupsLib, NAME, #NAME)) return;
57 CUPS_SHIM_ALL_FUNCS(CUPS_SHIM_LOAD
)
58 # undef CUPS_SHIM_LOAD
60 // Set mInitOkay only if all cups functions are loaded successfully.