diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /widget/nsCUPSShim.cpp | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | widget/nsCUPSShim.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/widget/nsCUPSShim.cpp b/widget/nsCUPSShim.cpp new file mode 100644 index 0000000000..1da189c725 --- /dev/null +++ b/widget/nsCUPSShim.cpp @@ -0,0 +1,64 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsDebug.h" +#include "nsString.h" +#include "nsCUPSShim.h" +#include "mozilla/ArrayUtils.h" +#include "prlink.h" + +#ifdef CUPS_SHIM_RUNTIME_LINK + +// TODO: This is currently pointless as we always use the compile-time linked +// version of CUPS, but in the future this may become a configure option. +// We also cannot use NSPR's library suffix support, since that cannot handle +// version number suffixes. +# ifdef XP_MACOSX +static const char gCUPSLibraryName[] = "libcups.2.dylib"; +# else +static const char gCUPSLibraryName[] = "libcups.so.2"; +# endif + +template <typename FuncT> +static bool LoadCupsFunc(PRLibrary*& lib, FuncT*& dest, + const char* const name) { + dest = (FuncT*)PR_FindSymbol(lib, name); + if (MOZ_UNLIKELY(!dest)) { +# ifdef DEBUG + nsAutoCString msg(name); + msg.AppendLiteral(" not found in CUPS library"); + NS_WARNING(msg.get()); +# endif +# ifndef MOZ_TSAN + // With TSan, we cannot unload libcups once we have loaded it because + // TSan does not support unloading libraries that are matched from its + // suppression list. Hence we just keep the library loaded in TSan builds. + PR_UnloadLibrary(lib); +# endif + lib = nullptr; + return false; + } + return true; +} + +nsCUPSShim::nsCUPSShim() { + mCupsLib = PR_LoadLibrary(gCUPSLibraryName); + if (!mCupsLib) { + return; + } + + // This is a macro so that it could also load from libcups if we are + // configured to use it as a compile-time dependency. +# define CUPS_SHIM_LOAD(NAME) \ + if (!LoadCupsFunc(mCupsLib, NAME, #NAME)) return; + CUPS_SHIM_ALL_FUNCS(CUPS_SHIM_LOAD) +# undef CUPS_SHIM_LOAD + + // Set mInitOkay only if all cups functions are loaded successfully. + mInitOkay = true; +} + +#endif |