libopenraw
file.cpp
1 /*
2  * libopenraw - file.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 #include <fcntl.h>
22 #include <string>
23 
24 #include "libopenraw/consts.h"
25 #include "libopenraw/io.h"
26 
27 #include "io/stream.hpp"
28 #include "file.hpp"
29 
30 namespace OpenRaw {
31  namespace IO {
32 
33  File::File(const char *filename)
34  : OpenRaw::IO::Stream(filename),
35  m_methods(::get_default_io_methods()),
36  m_ioRef(NULL)
37  {
38  }
39 
40  File::~File()
41  {
42  if (m_ioRef) {
43  close();
44  }
45  }
46 
47  File::Error File::open()
48  {
49  m_ioRef = ::raw_open(m_methods, get_path().c_str(), O_RDONLY);
50  if (m_ioRef == NULL) {
51  return OR_ERROR_CANT_OPEN;
52  }
53  return OR_ERROR_NONE;
54  }
55 
57  {
58  int result = ::raw_close(m_ioRef);
59  m_ioRef = NULL;
60  return result;
61  }
62 
63  int File::seek(off_t offset, int whence)
64  {
65  return ::raw_seek(m_ioRef, offset, whence);
66  }
67 
68  int File::read(void *buf, size_t count)
69  {
70  return ::raw_read(m_ioRef, buf, count);
71  }
72 
73  off_t File::filesize()
74  {
75  return ::raw_filesize(m_ioRef);
76  }
77 
78  }
79 }
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard. I guess it failed.
Definition: arwfile.cpp:30
virtual int read(void *buf, size_t count) override
Definition: file.cpp:68
virtual int close() override
Definition: file.cpp:56
File(const char *filename)
Definition: file.cpp:33
const std::string & get_path() const
Definition: stream.hpp:75
virtual int seek(off_t offset, int whence) override
Definition: file.cpp:63
virtual Error open() override
Definition: file.cpp:47
base virtual class for IO
Definition: stream.hpp:41