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 <errno.h> 10 #include <unistd.h> 11 12 13 namespace BPackageKit { 14 15 namespace BHPKG { 16 17 18 BFDDataReader::BFDDataReader(int fd) 19 : 20 fFD(fd) 21 { 22 } 23 24 25 status_t 26 BFDDataReader::ReadData(off_t offset, void* buffer, size_t size) 27 { 28 ssize_t bytesRead = pread(fFD, buffer, size, offset); 29 if (bytesRead < 0) 30 return errno; 31 return (size_t)bytesRead == size ? B_OK : B_ERROR; 32 } 33 34 35 } // namespace BHPKG 36 37 } // namespace BPackageKit 38