19a8c1339SIngo Weinhold/*
29a8c1339SIngo Weinhold * Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
39a8c1339SIngo Weinhold * Distributed under the terms of the MIT License.
49a8c1339SIngo Weinhold */
59a8c1339SIngo Weinhold
69a8c1339SIngo Weinhold
79a8c1339SIngo Weinhold#include <package/hpkg/DataReader.h>
89a8c1339SIngo Weinhold
99a8c1339SIngo Weinhold#include <errno.h>
109a8c1339SIngo Weinhold#include <unistd.h>
119a8c1339SIngo Weinhold
129a8c1339SIngo Weinhold
139a8c1339SIngo Weinholdnamespace BPackageKit {
149a8c1339SIngo Weinhold
159a8c1339SIngo Weinholdnamespace BHPKG {
169a8c1339SIngo Weinhold
179a8c1339SIngo Weinhold
189a8c1339SIngo WeinholdBFDDataReader::BFDDataReader(int fd)
199a8c1339SIngo Weinhold	:
209a8c1339SIngo Weinhold	fFD(fd)
219a8c1339SIngo Weinhold{
229a8c1339SIngo Weinhold}
239a8c1339SIngo Weinhold
249a8c1339SIngo Weinhold
2516e5e5e4SIngo Weinholdvoid
2616e5e5e4SIngo WeinholdBFDDataReader::SetFD(int fd)
2716e5e5e4SIngo Weinhold{
2816e5e5e4SIngo Weinhold	fFD = fd;
2916e5e5e4SIngo Weinhold}
3016e5e5e4SIngo Weinhold
3116e5e5e4SIngo Weinhold
329a8c1339SIngo Weinholdstatus_t
339a8c1339SIngo WeinholdBFDDataReader::ReadData(off_t offset, void* buffer, size_t size)
349a8c1339SIngo Weinhold{
359a8c1339SIngo Weinhold	ssize_t bytesRead = pread(fFD, buffer, size, offset);
369a8c1339SIngo Weinhold	if (bytesRead < 0)
379a8c1339SIngo Weinhold		return errno;
389a8c1339SIngo Weinhold	return (size_t)bytesRead == size ? B_OK : B_ERROR;
399a8c1339SIngo Weinhold}
409a8c1339SIngo Weinhold
419a8c1339SIngo Weinhold
429a8c1339SIngo Weinhold}	// namespace BHPKG
439a8c1339SIngo Weinhold
449a8c1339SIngo Weinhold}	// namespace BPackageKit
45