Bug 1671598 [wpt PR 26128] - [AspectRatio] Fix divide by zero with a small float...
[gecko.git] / widget / nsCUPSShim.cpp
bloba45799ab349176bbf499a0458ace557bf539151b
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/. */
7 #include "nsDebug.h"
8 #include "nsString.h"
9 #include "nsCUPSShim.h"
10 #include "mozilla/ArrayUtils.h"
11 #include "prlink.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.
19 # ifdef XP_MACOSX
20 static const char gCUPSLibraryName[] = "libcups.2.dylib";
21 # else
22 static const char gCUPSLibraryName[] = "libcups.so.2";
23 # endif
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)) {
30 # ifdef DEBUG
31 nsAutoCString msg(name);
32 msg.AppendLiteral(" not found in CUPS library");
33 NS_WARNING(msg.get());
34 # endif
35 # ifndef MOZ_TSAN
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);
40 # endif
41 lib = nullptr;
42 return false;
44 return true;
47 bool nsCUPSShim::Init() {
48 mozilla::OffTheBooksMutexAutoLock lock(mInitMutex);
49 if (mInited) {
50 return true;
53 mCupsLib = PR_LoadLibrary(gCUPSLibraryName);
54 if (!mCupsLib) {
55 return false;
58 // This is a macro so that it could also load from libcups if we are configured
59 // to use it as a compile-time dependency.
60 # define CUPS_SHIM_LOAD(NAME) \
61 if (!LoadCupsFunc(mCupsLib, NAME, #NAME)) return false;
62 CUPS_SHIM_ALL_FUNCS(CUPS_SHIM_LOAD)
63 # undef CUPS_SHIM_LOAD
64 mInited = true;
65 return true;
68 #else // CUPS_SHIM_RUNTIME_LINK
70 bool nsCUPSShim::Init() {
71 mInited = true;
72 return true;
75 #endif