Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/widget/gtk/nsCUPSShim.cpp
Line
Count
Source (jump to first uncovered line)
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
nsCUPSShim::Init()
30
0
{
31
0
    mCupsLib = PR_LoadLibrary("libcups.so.2");
32
0
    if (!mCupsLib)
33
0
        return false;
34
0
35
0
    // List of symbol pointers. Must match gSymName[] defined above.
36
0
    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
0
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
            nsAutoCString msg(gSymName[i]);
50
            msg.AppendLiteral(" not found in CUPS library");
51
            NS_WARNING(msg.get());
52
#endif
53
            PR_UnloadLibrary(mCupsLib);
54
0
            mCupsLib = nullptr;
55
0
            return false;
56
0
        }
57
0
    }
58
0
    return true;
59
0
}