1 /*
2 * Copyright 2019 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 #include <unistd.h>
17
18 #include "FileInputStream.h"
19
20 namespace parselib {
21
read(void * buff,int32_t numBytes)22 int32_t FileInputStream::read(void *buff, int32_t numBytes) {
23 return ::read(mFH, buff, numBytes);
24 }
25
peek(void * buff,int32_t numBytes)26 int32_t FileInputStream::peek(void *buff, int32_t numBytes) {
27 int32_t numRead = ::read(mFH, buff, numBytes);
28 ::lseek(mFH, -numBytes, SEEK_CUR);
29 return numRead;
30 }
31
advance(int32_t numBytes)32 void FileInputStream::advance(int32_t numBytes) {
33 if (numBytes > 0) {
34 ::lseek(mFH, numBytes, SEEK_CUR);
35 }
36 }
37
getPos()38 int32_t FileInputStream::getPos() {
39 return ::lseek(mFH, 0L, SEEK_CUR);
40 }
41
setPos(int32_t pos)42 void FileInputStream::setPos(int32_t pos) {
43 if (pos > 0) {
44 ::lseek(mFH, pos, SEEK_SET);
45 }
46 }
47
48 } /* namespace parselib */
49