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
11#include <fs_attr.h>
12
13
14namespace BPackageKit {
15
16namespace BHPKG {
17
18
19BAttributeDataReader::BAttributeDataReader(int fd, const char* attribute,
20	uint32 type)
21	:
22	fFD(fd),
23	fType(type),
24	fAttribute(attribute)
25{
26}
27
28
29status_t
30BAttributeDataReader::ReadData(off_t offset, void* buffer, size_t size)
31{
32	ssize_t bytesRead = fs_read_attr(fFD, fAttribute, fType, offset, buffer,
33		size);
34	if (bytesRead < 0)
35		return errno;
36	return (size_t)bytesRead == size ? B_OK : B_ERROR;
37}
38
39
40}	// namespace BHPKG
41
42}	// namespace BPackageKit
43