1 // Copyright (c) 2012 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.
9 #include "mkvwriter.hpp"
12 #include <share.h> // for _SH_DENYWR
19 MkvWriter::MkvWriter() : file_(NULL), writer_owns_file_(true) {}
21 MkvWriter::MkvWriter(FILE* fp) : file_(fp), writer_owns_file_(false) {}
23 MkvWriter::~MkvWriter() { Close(); }
25 int32 MkvWriter::Write(const void* buffer, uint32 length) {
35 const size_t bytes_written = fwrite(buffer, 1, length, file_);
37 return (bytes_written == length) ? 0 : -1;
40 bool MkvWriter::Open(const char* filename) {
48 file_ = _fsopen(filename, "wb", _SH_DENYWR);
50 file_ = fopen(filename, "wb");
57 void MkvWriter::Close() {
58 if (file_ && writer_owns_file_) {
64 int64 MkvWriter::Position() const {
69 return _ftelli64(file_);
75 int32 MkvWriter::Position(int64 position) {
80 return _fseeki64(file_, position, SEEK_SET);
82 return fseek(file_, position, SEEK_SET);
86 bool MkvWriter::Seekable() const { return true; }
88 void MkvWriter::ElementStartNotify(uint64, int64) {}
90 } // namespace mkvmuxer