OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef OTS_FILE_STREAM_H_ | |
6 #define OTS_FILE_STREAM_H_ | |
7 | |
8 #include "opentype-sanitiser.h" | |
9 | |
10 namespace ots { | |
11 | |
12 // An OTSStream implementation for testing. | |
13 class FILEStream : public OTSStream { | |
14 public: | |
15 explicit FILEStream(FILE *stream) | |
16 : file_(stream), position_(0) { | |
17 } | |
18 | |
19 ~FILEStream() { | |
20 if (file_) | |
21 fclose(file_); | |
22 } | |
23 | |
24 bool WriteRaw(const void *data, size_t length) { | |
25 if (!file_ || ::fwrite(data, length, 1, file_) == 1) { | |
26 position_ += length; | |
27 return true; | |
28 } | |
29 return false; | |
30 } | |
31 | |
32 bool Seek(off_t position) { | |
33 #if defined(_WIN32) | |
34 if (!file_ || !::_fseeki64(file_, position, SEEK_SET)) { | |
35 position_ = position; | |
36 return true; | |
37 } | |
38 #else | |
39 if (!file_ || !::fseeko(file_, position, SEEK_SET)) { | |
40 position_ = position; | |
41 return true; | |
42 } | |
43 #endif // defined(_WIN32) | |
44 return false; | |
45 } | |
46 | |
47 off_t Tell() const { | |
48 return position_; | |
49 } | |
50 | |
51 private: | |
52 FILE * const file_; | |
53 off_t position_; | |
54 }; | |
55 | |
56 } // namespace ots | |
57 | |
58 #endif // OTS_FILE_STREAM_H_ | |
OLD | NEW |