LCOV - code coverage report
Current view: top level - widget/gtk - nsCUPSShim.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 21 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       6             : 
       7             : #include "nsDebug.h"
       8             : #include "nsString.h"
       9             : #include "nsCUPSShim.h"
      10             : #include "mozilla/ArrayUtils.h"
      11             : #include "prlink.h"
      12             : 
      13             : 
      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);
      26             : 
      27             : 
      28             : bool
      29           0 : nsCUPSShim::Init()
      30             : {
      31           0 :     mCupsLib = PR_LoadLibrary("libcups.so.2");
      32           0 :     if (!mCupsLib)
      33           0 :         return false;
      34             : 
      35             :     // List of symbol pointers. Must match gSymName[] defined above.
      36             :     void **symAddr[] = {
      37           0 :         (void **)&mCupsAddOption,
      38           0 :         (void **)&mCupsFreeDests,
      39           0 :         (void **)&mCupsGetDest,
      40           0 :         (void **)&mCupsGetDests,
      41           0 :         (void **)&mCupsPrintFile,
      42           0 :         (void **)&mCupsTempFd,
      43           0 :     };
      44             : 
      45           0 :     for (int i = gSymNameCt; i--; ) {
      46           0 :         *(symAddr[i]) = PR_FindSymbol(mCupsLib, gSymName[i]);
      47           0 :         if (! *(symAddr[i])) {
      48             : #ifdef DEBUG
      49           0 :             nsAutoCString msg(gSymName[i]);
      50           0 :             msg.AppendLiteral(" not found in CUPS library");
      51           0 :             NS_WARNING(msg.get());
      52             : #endif
      53           0 :             PR_UnloadLibrary(mCupsLib);
      54           0 :             mCupsLib = nullptr;
      55           0 :             return false;
      56             :         }
      57             :     }
      58           0 :     return true;
      59             : }

Generated by: LCOV version 1.13