blob: f2cae5b1d518cccd5c2e2dd01a114883974114e2 [file] [log] [blame]
Brian Carlstromcd60ac72013-01-20 17:09:51 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "vector_output_stream.h"
18
Andreas Gampe57943812017-12-06 21:39:13 -080019#include <android-base/logging.h>
Brian Carlstromcd60ac72013-01-20 17:09:51 -080020
21namespace art {
Vladimir Marko74527972016-11-29 15:57:32 +000022namespace linker {
Brian Carlstromcd60ac72013-01-20 17:09:51 -080023
Ian Rogers0279ebb2014-10-08 17:27:48 -070024VectorOutputStream::VectorOutputStream(const std::string& location, std::vector<uint8_t>* vector)
Vladimir Marko131980f2015-12-03 18:29:23 +000025 : OutputStream(location), offset_(vector->size()), vector_(vector) {}
Brian Carlstromcd60ac72013-01-20 17:09:51 -080026
Brian Carlstrom49a0f152013-01-22 17:17:36 -080027off_t VectorOutputStream::Seek(off_t offset, Whence whence) {
28 CHECK(whence == kSeekSet || whence == kSeekCurrent || whence == kSeekEnd) << whence;
29 off_t new_offset = 0;
Brian Carlstromcd60ac72013-01-20 17:09:51 -080030 switch (whence) {
Brian Carlstrom49a0f152013-01-22 17:17:36 -080031 case kSeekSet: {
Brian Carlstromcd60ac72013-01-20 17:09:51 -080032 new_offset = offset;
33 break;
34 }
Brian Carlstrom49a0f152013-01-22 17:17:36 -080035 case kSeekCurrent: {
Brian Carlstromcd60ac72013-01-20 17:09:51 -080036 new_offset = offset_ + offset;
37 break;
38 }
Brian Carlstrom49a0f152013-01-22 17:17:36 -080039 case kSeekEnd: {
Ian Rogers0279ebb2014-10-08 17:27:48 -070040 new_offset = vector_->size() + offset;
Brian Carlstromcd60ac72013-01-20 17:09:51 -080041 break;
42 }
Brian Carlstromcd60ac72013-01-20 17:09:51 -080043 }
44 EnsureCapacity(new_offset);
45 offset_ = new_offset;
46 return offset_;
47}
48
Vladimir Marko74527972016-11-29 15:57:32 +000049} // namespace linker
Brian Carlstromcd60ac72013-01-20 17:09:51 -080050} // namespace art