src/platform/qt/VFileDevice.cpp (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
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#include "VFileDevice.h"
7
8extern "C" {
9#include "util/vfs.h"
10}
11
12using namespace QGBA;
13
14VFileDevice::VFileDevice(VFile* vf, QObject* parent)
15 : QIODevice(parent)
16 , m_vf(vf)
17{
18 // Nothing to do
19}
20
21qint64 VFileDevice::readData(char* data, qint64 maxSize) {
22 return m_vf->read(m_vf, data, maxSize);
23}
24
25qint64 VFileDevice::writeData(const char* data, qint64 maxSize) {
26 return m_vf->write(m_vf, data, maxSize);
27}
28
29qint64 VFileDevice::size() const {
30 // TODO: Add size method to VFile so this can be actually const
31 ssize_t pos = m_vf->seek(m_vf, 0, SEEK_CUR);
32 qint64 size = m_vf->seek(m_vf, 0, SEEK_END);
33 m_vf->seek(m_vf, pos, SEEK_SET);
34 return size;
35}