17cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines/* 27cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * Copyright 2012, The Android Open Source Project 37cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * 47cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * Licensed under the Apache License, Version 2.0 (the "License"); 57cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * you may not use this file except in compliance with the License. 67cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * You may obtain a copy of the License at 77cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * 87cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * http://www.apache.org/licenses/LICENSE-2.0 97cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * 107cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * Unless required by applicable law or agreed to in writing, software 117cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * distributed under the License is distributed on an "AS IS" BASIS, 127cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * See the License for the specific language governing permissions and 147cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines * limitations under the License. 157cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines */ 167cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines 177cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines// Defines utility allowing files for bitcode input wrapping. 187cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines 197cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#ifndef FILE_WRAPPER_INPUT_H__ 207cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#define FILE_WRAPPER_INPUT_H__ 217cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines 227cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#include <stdio.h> 237cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines 247cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#include "bcinfo/Wrap/support_macros.h" 257cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#include "bcinfo/Wrap/wrapper_input.h" 267cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines 277cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines// Define a class to wrap named files. 287cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hinesclass FileWrapperInput : public WrapperInput { 297cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines public: 307cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines FileWrapperInput(const char* _name); 317cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines ~FileWrapperInput(); 327cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // Tries to read the requested number of bytes into the buffer. Returns the 337cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // actual number of bytes read. 347cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines virtual size_t Read(uint8_t* buffer, size_t wanted); 357cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // Returns true if at end of file. Note: May return false 367cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // until Read is called, and returns 0. 377cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines virtual bool AtEof(); 387cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // Returns the size of the file (in bytes). 397cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines virtual off_t Size(); 407cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // Moves to the given offset within the file. Returns 417cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // false if unable to move to that position. 427cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines virtual bool Seek(uint32_t pos); 437cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines private: 447cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // The name of the file. 457cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines const char* _name; 467cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // True once eof has been encountered. 477cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines bool _at_eof; 487cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // True if size has been computed. 497cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines bool _size_found; 507cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // The size of the file. 517cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines off_t _size; 527cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines // The corresponding (opened) file. 537cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines FILE* _file; 547cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines private: 557cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines DISALLOW_CLASS_COPY_AND_ASSIGN(FileWrapperInput); 567cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines}; 577cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines 587cd4c49d575478b2380f129dcd376a4e5e37939cStephen Hines#endif // FILE_WRAPPER_INPUT_H__ 59