1 // -*- mode: C++; tab-width: 4 -*-
2 // vi: ts=4
3
4 /*
5 * Copyright (c) 2010, Patrick A. Palmer and Leszek Godlewski.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * - Neither the name of Patrick A. Palmer nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <cstdio>
36
37 #include <OpenImageIO/filesystem.h>
38
39 #include "CineonStream.h"
40
41
42 namespace cineon {
43
OutStream()44 OutStream::OutStream() : fp(0)
45 {
46 }
47
48
~OutStream()49 OutStream::~OutStream()
50 {
51 }
52
53
Open(const char * f)54 bool OutStream::Open(const char *f)
55 {
56 if (this->fp)
57 this->Close();
58 if ((this->fp = OIIO::Filesystem::fopen(f, "wb")) == 0)
59 return false;
60
61 return true;
62 }
63
64
Close()65 void OutStream::Close()
66 {
67 if (this->fp)
68 {
69 ::fclose(this->fp);
70 this->fp = 0;
71 }
72 }
73
74
Write(void * buf,const size_t size)75 size_t OutStream::Write(void *buf, const size_t size)
76 {
77 if (this->fp == 0)
78 return false;
79 return ::fwrite(buf, 1, size, this->fp);
80 }
81
82
Seek(long offset,Origin origin)83 bool OutStream::Seek(long offset, Origin origin)
84 {
85 int o = 0;
86 switch (origin)
87 {
88 case kCurrent:
89 o = SEEK_CUR;
90 break;
91 case kEnd:
92 o = SEEK_END;
93 break;
94 case kStart:
95 o = SEEK_SET;
96 break;
97 }
98
99 if (this->fp == 0)
100 return false;
101 return (::fseek(this->fp, offset, o) == 0);
102 }
103
104
Flush()105 void OutStream::Flush()
106 {
107 if (this->fp)
108 ::fflush(this->fp);
109 }
110
111 }
112
113
114
115
116
117
118