1/*
2 * Copyright 2012, 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// Defines utility allowing files for bitcode input wrapping.
18
19#ifndef FILE_WRAPPER_INPUT_H__
20#define FILE_WRAPPER_INPUT_H__
21
22#include <stdio.h>
23
24#include "bcinfo/Wrap/support_macros.h"
25#include "bcinfo/Wrap/wrapper_input.h"
26
27// Define a class to wrap named files.
28class FileWrapperInput : public WrapperInput {
29 public:
30  FileWrapperInput(const char* _name);
31  ~FileWrapperInput();
32  // Tries to read the requested number of bytes into the buffer. Returns the
33  // actual number of bytes read.
34  virtual size_t Read(uint8_t* buffer, size_t wanted);
35  // Returns true if at end of file. Note: May return false
36  // until Read is called, and returns 0.
37  virtual bool AtEof();
38  // Returns the size of the file (in bytes).
39  virtual off_t Size();
40  // Moves to the given offset within the file. Returns
41  // false if unable to move to that position.
42  virtual bool Seek(uint32_t pos);
43 private:
44  // The name of the file.
45  const char* _name;
46  // True once eof has been encountered.
47  bool _at_eof;
48  // True if size has been computed.
49  bool _size_found;
50  // The size of the file.
51  off_t _size;
52  // The corresponding (opened) file.
53  FILE* _file;
54 private:
55  DISALLOW_CLASS_COPY_AND_ASSIGN(FileWrapperInput);
56};
57
58#endif // FILE_WRAPPER_INPUT_H__
59