Diffstat (limited to 'core/multimedia/opieplayer/modplug/memfile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/modplug/memfile.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/modplug/memfile.cpp b/core/multimedia/opieplayer/modplug/memfile.cpp new file mode 100644 index 0000000..8a29997 --- a/dev/null +++ b/core/multimedia/opieplayer/modplug/memfile.cpp | |||
@@ -0,0 +1,76 @@ | |||
1 | /* This file is part of the KDE project | ||
2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; see the file COPYING. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | #include "memfile.h" | ||
21 | |||
22 | #include <unistd.h> | ||
23 | #include <sys/mman.h> | ||
24 | |||
25 | MemFile::MemFile() | ||
26 | { | ||
27 | } | ||
28 | |||
29 | MemFile::MemFile( const QString &name ) | ||
30 | : QFile( name ) | ||
31 | { | ||
32 | } | ||
33 | |||
34 | MemFile::~MemFile() | ||
35 | { | ||
36 | close(); | ||
37 | } | ||
38 | |||
39 | void MemFile::close() | ||
40 | { | ||
41 | unmap(); | ||
42 | QFile::close(); | ||
43 | } | ||
44 | |||
45 | void MemFile::unmap() | ||
46 | { | ||
47 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) | ||
48 | if ( m_data.data() ) | ||
49 | { | ||
50 | munmap( m_data.data(), m_data.size() ); | ||
51 | m_data.resetRawData( m_data.data(), m_data.size() ); | ||
52 | } | ||
53 | #endif | ||
54 | } | ||
55 | |||
56 | QByteArray &MemFile::data() | ||
57 | { | ||
58 | if ( !m_data.data() ) | ||
59 | { | ||
60 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) | ||
61 | const char *rawData = (const char *)mmap( 0, size(), PROT_READ, | ||
62 | MAP_SHARED, handle(), 0 ); | ||
63 | if ( rawData ) | ||
64 | { | ||
65 | m_data.setRawData( rawData, size() ); | ||
66 | return m_data; | ||
67 | } | ||
68 | else | ||
69 | qDebug( "MemFile: mmap() failed!" ); | ||
70 | // fallback | ||
71 | #endif | ||
72 | m_data = readAll(); | ||
73 | } | ||
74 | return m_data; | ||
75 | } | ||
76 | |||