1 // Copyright (c) 2010 The WebM project authors. All Rights Reserved.
\r
3 // Use of this source code is governed by a BSD-style license
\r
4 // that can be found in the LICENSE file in the root of the source
\r
5 // tree. An additional intellectual property rights grant can be found
\r
6 // in the file PATENTS. All contributing project authors may
\r
7 // be found in the AUTHORS file in the root of the source tree.
\r
9 #include "mkvreader.hpp"
\r
16 MkvReader::MkvReader() :
\r
21 MkvReader::~MkvReader()
\r
26 int MkvReader::Open(const char* fileName)
\r
28 if (fileName == NULL)
\r
35 const errno_t e = fopen_s(&m_file, fileName, "rb");
\r
40 m_file = fopen(fileName, "rb");
\r
47 int status = _fseeki64(m_file, 0L, SEEK_END);
\r
52 m_length = _ftelli64(m_file);
\r
54 fseek(m_file, 0L, SEEK_END);
\r
55 m_length = ftell(m_file);
\r
57 assert(m_length >= 0);
\r
60 status = _fseeki64(m_file, 0L, SEEK_SET);
\r
65 fseek(m_file, 0L, SEEK_SET);
\r
71 void MkvReader::Close()
\r
80 int MkvReader::Length(long long* total, long long* available)
\r
89 *available = m_length;
\r
94 int MkvReader::Read(long long offset, long len, unsigned char* buffer)
\r
108 if (offset >= m_length)
\r
112 const int status = _fseeki64(m_file, offset, SEEK_SET);
\r
117 fseek(m_file, offset, SEEK_SET);
\r
120 const size_t size = fread(buffer, 1, len, m_file);
\r
122 if (size < size_t(len))
\r
125 return 0; //success
\r
128 } //end namespace mkvparser
\r