Bumping manifests a=b2g-bump
[gecko.git] / widget / gtk / nsCUPSShim.cpp
blobd05da307f8626aff4b3b51cd3f1c2fddcc165fbb
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set tabstop=8 softtabstop=4 shiftwidth=4 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"
14 // List of symbols to find in libcups. Must match symAddr[] defined in Init().
15 // Making this an array of arrays instead of pointers allows storing the
16 // whole thing in read-only memory.
17 static const char gSymName[][sizeof("cupsPrintFile")] = {
18 { "cupsAddOption" },
19 { "cupsFreeDests" },
20 { "cupsGetDest" },
21 { "cupsGetDests" },
22 { "cupsPrintFile" },
23 { "cupsTempFd" },
25 static const int gSymNameCt = mozilla::ArrayLength(gSymName);
28 bool
29 nsCUPSShim::Init()
31 mCupsLib = PR_LoadLibrary("libcups.so.2");
32 if (!mCupsLib)
33 return false;
35 // List of symbol pointers. Must match gSymName[] defined above.
36 void **symAddr[] = {
37 (void **)&mCupsAddOption,
38 (void **)&mCupsFreeDests,
39 (void **)&mCupsGetDest,
40 (void **)&mCupsGetDests,
41 (void **)&mCupsPrintFile,
42 (void **)&mCupsTempFd,
45 for (int i = gSymNameCt; i--; ) {
46 *(symAddr[i]) = PR_FindSymbol(mCupsLib, gSymName[i]);
47 if (! *(symAddr[i])) {
48 #ifdef DEBUG
49 nsAutoCString msg(gSymName[i]);
50 msg.AppendLiteral(" not found in CUPS library");
51 NS_WARNING(msg.get());
52 #endif
53 PR_UnloadLibrary(mCupsLib);
54 mCupsLib = nullptr;
55 return false;
58 return true;