1 /* 2 * Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <package/hpkg/DataReader.h> 8 9 #include <string.h> 10 11 12 namespace BPackageKit { 13 14 namespace BHPKG { 15 16 17 // #pragma mark - BDataReader 18 19 20 BDataReader::~BDataReader() 21 { 22 } 23 24 25 // #pragma mark - BBufferDataReader 26 27 28 BBufferDataReader::BBufferDataReader(const void* data, size_t size) 29 : 30 fData(data), 31 fSize(size) 32 { 33 } 34 35 36 status_t 37 BBufferDataReader::ReadData(off_t offset, void* buffer, size_t size) 38 { 39 if (size == 0) 40 return B_OK; 41 42 if (offset < 0) 43 return B_BAD_VALUE; 44 45 if (size > fSize || offset > (off_t)fSize - (off_t)size) 46 return B_ERROR; 47 48 memcpy(buffer, (const uint8*)fData + offset, size); 49 return B_OK; 50 } 51 52 53 } // namespace BHPKG 54 55 } // namespace BPackageKit 56