OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef OTS_FILE_STREAM_H_ | 5 #ifndef OTS_FILE_STREAM_H_ |
6 #define OTS_FILE_STREAM_H_ | 6 #define OTS_FILE_STREAM_H_ |
7 | 7 |
8 #include "opentype-sanitiser.h" | 8 #include "opentype-sanitiser.h" |
9 | 9 |
10 namespace ots { | 10 namespace ots { |
11 | 11 |
12 // An OTSStream implementation for testing. | |
12 class FILEStream : public OTSStream { | 13 class FILEStream : public OTSStream { |
13 public: | 14 public: |
14 explicit FILEStream(FILE *stream) | 15 explicit FILEStream(FILE *stream) |
15 : file_(stream) { | 16 : file_(stream), position_(0) { |
16 } | 17 } |
17 | 18 |
18 ~FILEStream() { | 19 ~FILEStream() { |
19 } | 20 } |
20 | 21 |
21 bool WriteRaw(const void *data, size_t length) { | 22 bool WriteRaw(const void *data, size_t length) { |
22 return fwrite(data, length, 1, file_) == 1; | 23 if (::fwrite(data, length, 1, file_) == 1) { |
Evan Martin
2009/11/23 17:44:19
Does this function succeed when writing to /dev/nu
Yusuke Sato
2009/11/23 17:59:24
Yes, at least on Linux 2.6.
| |
24 position_ += length; | |
25 return true; | |
26 } | |
27 return false; | |
23 } | 28 } |
24 | 29 |
25 bool Seek(off_t position) { | 30 bool Seek(off_t position) { |
26 return fseek(file_, position, SEEK_SET) == 0; | 31 if (!::fseeko(file_, position, SEEK_SET)) { |
32 position_ = position; | |
33 return true; | |
34 } | |
35 return false; | |
27 } | 36 } |
28 | 37 |
29 off_t Tell() const { | 38 off_t Tell() const { |
30 return ftell(file_); | 39 return position_; |
31 } | 40 } |
32 | 41 |
33 private: | 42 private: |
34 FILE * const file_; | 43 FILE * const file_; |
44 off_t position_; | |
35 }; | 45 }; |
36 | 46 |
37 } // namespace ots | 47 } // namespace ots |
38 | 48 |
39 #endif // OTS_FILE_STREAM_H_ | 49 #endif // OTS_FILE_STREAM_H_ |
OLD | NEW |