Coverage Report

Created: 2026-04-01 07:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/karchive/src/klimitediodevice.cpp
Line
Count
Source
1
/* This file is part of the KDE libraries
2
   SPDX-FileCopyrightText: 2001, 2002, 2007 David Faure <faure@kde.org>
3
4
   SPDX-License-Identifier: LGPL-2.0-or-later
5
*/
6
7
#include "klimitediodevice_p.h"
8
#include "loggingcategory.h"
9
10
#ifdef TEST_MODE
11
#define WARNING qWarning()
12
#else
13
0
#define WARNING qCWarning(KArchiveLog)
14
#endif
15
16
KLimitedIODevice::KLimitedIODevice(QIODevice *dev, qint64 start, qint64 length)
17
9.75k
    : m_dev(dev)
18
9.75k
    , m_start(start)
19
9.75k
    , m_length(length)
20
9.75k
{
21
    // qCDebug(KArchiveLog) << "start=" << start << "length=" << length;
22
23
9.75k
    const bool res = open(QIODevice::ReadOnly); // krazy:exclude=syscalls
24
    
25
    // KLimitedIODevice always returns true
26
9.75k
    Q_ASSERT(res);
27
28
9.75k
    if(!res) {
29
0
        WARNING << "failed to open LimitedIO device for reading.";
30
0
    }
31
9.75k
}
32
33
bool KLimitedIODevice::open(QIODevice::OpenMode m)
34
9.75k
{
35
    // qCDebug(KArchiveLog) << "m=" << m;
36
9.75k
    if (m & QIODevice::ReadOnly) {
37
        /*bool ok = false;
38
          if ( m_dev->isOpen() )
39
          ok = ( m_dev->mode() == QIODevice::ReadOnly );
40
          else
41
          ok = m_dev->open( m );
42
          if ( ok )*/
43
9.75k
        m_dev->seek(m_start); // No concurrent access !
44
9.75k
    } else {
45
0
        WARNING << "KLimitedIODevice::open only supports QIODevice::ReadOnly!";
46
0
    }
47
9.75k
    setOpenMode(QIODevice::ReadOnly);
48
9.75k
    return true;
49
9.75k
}
50
51
void KLimitedIODevice::close()
52
0
{
53
0
}
54
55
qint64 KLimitedIODevice::size() const
56
8.12k
{
57
8.12k
    return m_length;
58
8.12k
}
59
60
qint64 KLimitedIODevice::readData(char *data, qint64 maxlen)
61
21.8k
{
62
21.8k
    maxlen = qMin(maxlen, m_length - pos()); // Apply upper limit
63
21.8k
    return m_dev->read(data, maxlen);
64
21.8k
}
65
66
bool KLimitedIODevice::seek(qint64 pos)
67
0
{
68
0
    Q_ASSERT(pos <= m_length);
69
0
    pos = qMin(pos, m_length); // Apply upper limit
70
0
    bool ret = m_dev->seek(m_start + pos);
71
0
    if (ret) {
72
0
        QIODevice::seek(pos);
73
0
    }
74
0
    return ret;
75
0
}
76
77
qint64 KLimitedIODevice::bytesAvailable() const
78
538
{
79
538
    return QIODevice::bytesAvailable();
80
538
}
81
82
bool KLimitedIODevice::isSequential() const
83
9.51k
{
84
9.51k
    return m_dev->isSequential();
85
9.51k
}
86
87
#include "moc_klimitediodevice_p.cpp"