1 // Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 #include "mkvparser/mkvreader.h"
14 MkvReader::MkvReader() : m_file(NULL), reader_owns_file_(true) {}
16 MkvReader::MkvReader(FILE* fp) : m_file(fp), reader_owns_file_(false) {
20 MkvReader::~MkvReader() {
21 if (reader_owns_file_)
26 int MkvReader::Open(const char* fileName) {
34 const errno_t e = fopen_s(&m_file, fileName, "rb");
39 m_file = fopen(fileName, "rb");
44 return !GetFileSize();
47 bool MkvReader::GetFileSize() {
51 int status = _fseeki64(m_file, 0L, SEEK_END);
54 return false; // error
56 m_length = _ftelli64(m_file);
58 fseek(m_file, 0L, SEEK_END);
59 m_length = ftell(m_file);
61 assert(m_length >= 0);
67 status = _fseeki64(m_file, 0L, SEEK_SET);
70 return false; // error
72 fseek(m_file, 0L, SEEK_SET);
78 void MkvReader::Close() {
85 int MkvReader::Length(long long* total, long long* available) {
93 *available = m_length;
98 int MkvReader::Read(long long offset, long len, unsigned char* buffer) {
111 if (offset >= m_length)
115 const int status = _fseeki64(m_file, offset, SEEK_SET);
120 fseek(m_file, offset, SEEK_SET);
123 const size_t size = fread(buffer, 1, len, m_file);
125 if (size < size_t(len))
131 } // namespace mkvparser