OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Bazel Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #ifndef INCLUDED_THIRD_PARTY_IJAR_MAPPED_FILE_H |
| 16 #define INCLUDED_THIRD_PARTY_IJAR_MAPPED_FILE_H |
| 17 |
| 18 #include "third_party/ijar/common.h" |
| 19 |
| 20 namespace devtools_ijar { |
| 21 |
| 22 struct MappedInputFileImpl; |
| 23 struct MappedOutputFileImpl; |
| 24 |
| 25 // A memory mapped input file. |
| 26 class MappedInputFile { |
| 27 private: |
| 28 MappedInputFileImpl *impl_; |
| 29 |
| 30 protected: |
| 31 const char* errmsg_; |
| 32 bool opened_; |
| 33 u1* buffer_; |
| 34 size_t length_; |
| 35 |
| 36 public: |
| 37 MappedInputFile(const char* name); |
| 38 virtual ~MappedInputFile(); |
| 39 |
| 40 // If opening the file succeeded or not. |
| 41 bool Opened() const { return opened_; } |
| 42 |
| 43 // Description of the last error that happened. |
| 44 const char* Error() const { return errmsg_; } |
| 45 |
| 46 // The mapped contents of the file. |
| 47 u1* Buffer() const { return buffer_ ; } |
| 48 |
| 49 // The length of the file. |
| 50 size_t Length() const { return length_; } |
| 51 |
| 52 // Unmap a given number of bytes from the beginning of the file. |
| 53 void Discard(size_t bytes); |
| 54 int Close(); |
| 55 }; |
| 56 |
| 57 class MappedOutputFile { |
| 58 private: |
| 59 MappedOutputFileImpl *impl_; |
| 60 |
| 61 protected: |
| 62 const char* errmsg_; |
| 63 bool opened_; |
| 64 u1* buffer_; |
| 65 |
| 66 public: |
| 67 MappedOutputFile(const char* name, u8 estimated_size); |
| 68 virtual ~MappedOutputFile(); |
| 69 |
| 70 // If opening the file succeeded or not. |
| 71 bool Opened() const { return opened_; } |
| 72 |
| 73 // Description of the last error that happened. |
| 74 const char* Error() const { return errmsg_; } |
| 75 |
| 76 // The mapped contents of the file. |
| 77 u1* Buffer() const { return buffer_; } |
| 78 int Close(int size); |
| 79 }; |
| 80 |
| 81 } // namespace devtools_ijar |
| 82 #endif |
OLD | NEW |