libopenraw
streamclone.cpp
1/*
2 * libopenraw - streamclone.cpp
3 *
4 * Copyright (C) 2006-2016 Hubert Figuière
5 *
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
21
22#include <stdio.h>
23#include <memory>
24#include <string>
25
26#include "io/stream.hpp"
27#include "libopenraw/consts.h"
28
29#include "streamclone.hpp"
30
31
32namespace OpenRaw {
33namespace IO {
34
35StreamClone::StreamClone(const Stream::Ptr & clone,
36 off_t offset)
37 : Stream(clone->get_path().c_str()),
38 m_cloned(clone), m_offset(offset)
39{
40
41}
42
43StreamClone::~StreamClone()
44{
45}
46
47
48Stream::Error StreamClone::open()
49{
50 if (m_cloned == NULL) {
51 set_error(OR_ERROR_CLOSED_STREAM);
52 return OR_ERROR_CLOSED_STREAM;
53 }
54 m_cloned->seek(m_offset, SEEK_SET);
55 //no-op
56 //FIXME determine what is the policy for opening clone
57 //streams
58 return OR_ERROR_NONE;
59}
60
61int StreamClone::close()
62{
63 m_cloned = NULL;
64 return 0;
65}
66
67
68int StreamClone::seek(off_t offset, int whence)
69{
70 if (m_cloned == NULL) {
71 set_error(OR_ERROR_CLOSED_STREAM);
72 return -1;
73 }
74 if (whence == SEEK_SET) {
75 offset += m_offset;
76 }
77 int new_pos = m_cloned->seek(offset, whence);
78 new_pos -= m_offset;
79 return new_pos;
80}
81
82
83int StreamClone::read(void *buf, size_t count)
84{
85 if (m_cloned == NULL) {
86 set_error(OR_ERROR_CLOSED_STREAM);
87 return -1;
88 }
89 return m_cloned->read(buf, count);
90}
91
92
93off_t StreamClone::filesize()
94{
95 if (m_cloned == NULL) {
96 set_error(OR_ERROR_CLOSED_STREAM);
97 return -1;
98 }
99 return m_cloned->filesize() - m_offset;
100}
101
102}
103}
104/*
105 Local Variables:
106 mode:c++
107 c-file-style:"stroustrup"
108 c-file-offsets:((innamespace . 0))
109 tab-width:2
110 c-basic-offset:2
111 indent-tabs-mode:nil
112 fill-column:80
113 End:
114*/
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard....
Definition: arwfile.cpp:30