widget/gtk/nsCUPSShim.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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" },
    24 };
    25 static const int gSymNameCt = mozilla::ArrayLength(gSymName);
    28 bool
    29 nsCUPSShim::Init()
    30 {
    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,
    43     };
    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.Append(" not found in CUPS library");
    51             NS_WARNING(msg.get());
    52 #endif
    53             PR_UnloadLibrary(mCupsLib);
    54             mCupsLib = nullptr;
    55             return false;
    56         }
    57     }
    58     return true;
    59 }

mercurial