summaryrefslogtreecommitdiffstats
path: root/widget/gtk/nsCUPSShim.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /widget/gtk/nsCUPSShim.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'widget/gtk/nsCUPSShim.cpp')
-rw-r--r--widget/gtk/nsCUPSShim.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/widget/gtk/nsCUPSShim.cpp b/widget/gtk/nsCUPSShim.cpp
new file mode 100644
index 000000000..d05da307f
--- /dev/null
+++ b/widget/gtk/nsCUPSShim.cpp
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* ex: set tabstop=8 softtabstop=4 shiftwidth=4 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"
+
+
+// List of symbols to find in libcups. Must match symAddr[] defined in Init().
+// Making this an array of arrays instead of pointers allows storing the
+// whole thing in read-only memory.
+static const char gSymName[][sizeof("cupsPrintFile")] = {
+ { "cupsAddOption" },
+ { "cupsFreeDests" },
+ { "cupsGetDest" },
+ { "cupsGetDests" },
+ { "cupsPrintFile" },
+ { "cupsTempFd" },
+};
+static const int gSymNameCt = mozilla::ArrayLength(gSymName);
+
+
+bool
+nsCUPSShim::Init()
+{
+ mCupsLib = PR_LoadLibrary("libcups.so.2");
+ if (!mCupsLib)
+ return false;
+
+ // List of symbol pointers. Must match gSymName[] defined above.
+ void **symAddr[] = {
+ (void **)&mCupsAddOption,
+ (void **)&mCupsFreeDests,
+ (void **)&mCupsGetDest,
+ (void **)&mCupsGetDests,
+ (void **)&mCupsPrintFile,
+ (void **)&mCupsTempFd,
+ };
+
+ for (int i = gSymNameCt; i--; ) {
+ *(symAddr[i]) = PR_FindSymbol(mCupsLib, gSymName[i]);
+ if (! *(symAddr[i])) {
+#ifdef DEBUG
+ nsAutoCString msg(gSymName[i]);
+ msg.AppendLiteral(" not found in CUPS library");
+ NS_WARNING(msg.get());
+#endif
+ PR_UnloadLibrary(mCupsLib);
+ mCupsLib = nullptr;
+ return false;
+ }
+ }
+ return true;
+}