1 | /* |
---|---|
2 | This file is part of the KDE project |
3 | SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
6 | */ |
7 | |
8 | #include "kmemfile_p.h" |
9 | #include "ksycocadevices_p.h" |
10 | #include <QBuffer> |
11 | #include <QDataStream> |
12 | #include <QFile> |
13 | #include <fcntl.h> |
14 | |
15 | KSycocaAbstractDevice::~KSycocaAbstractDevice() |
16 | { |
17 | delete m_stream; |
18 | } |
19 | |
20 | QDataStream *&KSycocaAbstractDevice::stream() |
21 | { |
22 | if (!m_stream) { |
23 | m_stream = new QDataStream(device()); |
24 | m_stream->setVersion(QDataStream::Qt_5_3); |
25 | } |
26 | return m_stream; |
27 | } |
28 | |
29 | #if HAVE_MMAP |
30 | KSycocaMmapDevice::KSycocaMmapDevice(const char *sycoca_mmap, size_t sycoca_size) |
31 | { |
32 | m_buffer = new QBuffer; |
33 | m_buffer->setData(QByteArray::fromRawData(data: sycoca_mmap, size: sycoca_size)); |
34 | } |
35 | |
36 | KSycocaMmapDevice::~KSycocaMmapDevice() |
37 | { |
38 | delete m_buffer; |
39 | } |
40 | |
41 | QIODevice *KSycocaMmapDevice::device() |
42 | { |
43 | return m_buffer; |
44 | } |
45 | #endif |
46 | |
47 | KSycocaFileDevice::KSycocaFileDevice(const QString &path) |
48 | { |
49 | m_database = new QFile(path); |
50 | #ifndef Q_OS_WIN |
51 | (void)fcntl(fd: m_database->handle(), F_SETFD, FD_CLOEXEC); |
52 | #endif |
53 | } |
54 | |
55 | KSycocaFileDevice::~KSycocaFileDevice() |
56 | { |
57 | delete m_database; |
58 | } |
59 | |
60 | QIODevice *KSycocaFileDevice::device() |
61 | { |
62 | return m_database; |
63 | } |
64 | |
65 | #ifndef QT_NO_SHAREDMEMORY |
66 | KSycocaMemFileDevice::KSycocaMemFileDevice(const QString &path) |
67 | { |
68 | m_database = new KMemFile(path); |
69 | } |
70 | |
71 | KSycocaMemFileDevice::~KSycocaMemFileDevice() |
72 | { |
73 | delete m_database; |
74 | } |
75 | |
76 | QIODevice *KSycocaMemFileDevice::device() |
77 | { |
78 | return m_database; |
79 | } |
80 | #endif |
81 | |
82 | KSycocaBufferDevice::KSycocaBufferDevice() |
83 | { |
84 | m_buffer = new QBuffer; |
85 | } |
86 | |
87 | KSycocaBufferDevice::~KSycocaBufferDevice() |
88 | { |
89 | delete m_buffer; |
90 | } |
91 | |
92 | QIODevice *KSycocaBufferDevice::device() |
93 | { |
94 | return m_buffer; |
95 | } |
96 |