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 BFDDataReader(int fd)18BFDDataReader::BFDDataReader(int fd) 19 : 20 fFD(fd) 21 { 22 } 23 24 25 void SetFD(int fd)26BFDDataReader::SetFD(int fd) 27 { 28 fFD = fd; 29 } 30 31 32 status_t ReadData(off_t offset,void * buffer,size_t size)33BFDDataReader::ReadData(off_t offset, void* buffer, size_t size) 34 { 35 ssize_t bytesRead = pread(fFD, buffer, size, offset); 36 if (bytesRead < 0) 37 return errno; 38 return (size_t)bytesRead == size ? B_OK : B_ERROR; 39 } 40 41 42 } // namespace BHPKG 43 44 } // namespace BPackageKit 45