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 "mkvmuxer/mkvwriter.h"
12 #include <share.h> // for _SH_DENYWR
17 MkvWriter::MkvWriter() : file_(NULL), writer_owns_file_(true) {}
19 MkvWriter::MkvWriter(FILE* fp) : file_(fp), writer_owns_file_(false) {}
21 MkvWriter::~MkvWriter() { Close(); }
23 int32_t MkvWriter::Write(const void* buffer, uint32_t length) {
33 const size_t bytes_written = fwrite(buffer, 1, length, file_);
35 return (bytes_written == length) ? 0 : -1;
38 bool MkvWriter::Open(const char* filename) {
46 file_ = _fsopen(filename, "wb", _SH_DENYWR);
48 file_ = fopen(filename, "wb");
55 void MkvWriter::Close() {
56 if (file_ && writer_owns_file_) {
62 int64_t MkvWriter::Position() const {
67 return _ftelli64(file_);
73 int32_t MkvWriter::Position(int64_t position) {
78 return _fseeki64(file_, position, SEEK_SET);
80 return fseek(file_, position, SEEK_SET);
84 bool MkvWriter::Seekable() const { return true; }
86 void MkvWriter::ElementStartNotify(uint64_t, int64_t) {}
88 } // namespace mkvmuxer