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) {
22 MkvWriter::MkvWriter(FILE* fp): file_(fp), writer_owns_file_(false) {
25 MkvWriter::~MkvWriter() {
29 int32 MkvWriter::Write(const void* buffer, uint32 length) {
39 const size_t bytes_written = fwrite(buffer, 1, length, file_);
41 return (bytes_written == length) ? 0 : -1;
44 bool MkvWriter::Open(const char* filename) {
52 file_ = _fsopen(filename, "wb", _SH_DENYWR);
54 file_ = fopen(filename, "wb");
61 void MkvWriter::Close() {
62 if (file_ && writer_owns_file_) {
68 int64 MkvWriter::Position() const {
73 return _ftelli64(file_);
79 int32 MkvWriter::Position(int64 position) {
84 return _fseeki64(file_, position, SEEK_SET);
86 return fseek(file_, position, SEEK_SET);
90 bool MkvWriter::Seekable() const {
94 void MkvWriter::ElementStartNotify(uint64, int64) {
97 } // namespace mkvmuxer