summaryrefslogtreecommitdiff
path: root/src/data.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-06-24 22:23:41 +0100
committerCarl Hetherington <cth@carlh.net>2015-06-24 22:23:41 +0100
commit93d06f01683ec7ad351db329627b02d4fb23f4fa (patch)
treedd6f1a265b2965e8c177a7e14afa639bd699ae91 /src/data.cc
parent9e523d8a4062ad52330dff6c2ba50e54184c9bb2 (diff)
parent69f188e13db64d8a3b17e49351d0be0ac3676b99 (diff)
Merge.
Diffstat (limited to 'src/data.cc')
-rw-r--r--src/data.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/data.cc b/src/data.cc
new file mode 100644
index 00000000..7f390ead
--- /dev/null
+++ b/src/data.cc
@@ -0,0 +1,42 @@
+/*
+ Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "data.h"
+#include "util.h"
+#include "exceptions.h"
+#include <cstdio>
+
+using namespace dcp;
+
+Data::Data (boost::filesystem::path file)
+{
+ FILE* f = fopen_boost (file, "rb");
+ if (!f) {
+ throw FileError ("could not open file for reading", file, errno);
+ }
+
+ size = boost::filesystem::file_size (file);
+ data.reset (new uint8_t[size]);
+ size_t const read = fread (data.get(), 1, size, f);
+ fclose (f);
+
+ if (read != size) {
+ throw FileError ("could not read file", file, -1);
+ }
+}