Author: bonefish Date: 2009-11-15 09:39:45 +0100 (Sun, 15 Nov 2009) New Revision: 34053 Changeset: http://dev.haiku-os.org/changeset/34053/haiku Modified: haiku/trunk/src/bin/package/DataReader.cpp haiku/trunk/src/bin/package/DataReader.h Log: Added AttributeDataReader, a DataReader implementation for attributes. Modified: haiku/trunk/src/bin/package/DataReader.cpp =================================================================== --- haiku/trunk/src/bin/package/DataReader.cpp 2009-11-15 08:37:22 UTC (rev 34052) +++ haiku/trunk/src/bin/package/DataReader.cpp 2009-11-15 08:39:45 UTC (rev 34053) @@ -10,7 +10,9 @@ #include <string.h> #include <unistd.h> +#include <fs_attr.h> + // #pragma mark - DataReader @@ -39,6 +41,30 @@ } +// #pragma mark - AttributeDataReader + + +AttributeDataReader::AttributeDataReader(int fd, const char* attribute, + uint32 type) + : + fFD(fd), + fType(type), + fAttribute(attribute) +{ +} + + +status_t +AttributeDataReader::ReadData(off_t offset, void* buffer, size_t size) +{ + ssize_t bytesRead = fs_read_attr(fFD, fAttribute, fType, offset, buffer, + size); + if (bytesRead < 0) + return errno; + return (size_t)bytesRead == size ? B_OK : B_ERROR; +} + + // #pragma mark - BufferDataReader Modified: haiku/trunk/src/bin/package/DataReader.h =================================================================== --- haiku/trunk/src/bin/package/DataReader.h 2009-11-15 08:37:22 UTC (rev 34052) +++ haiku/trunk/src/bin/package/DataReader.h 2009-11-15 08:39:45 UTC (rev 34053) @@ -30,6 +30,21 @@ }; +class AttributeDataReader : public DataReader { +public: + AttributeDataReader(int fd, + const char* attribute, uint32 type); + + virtual status_t ReadData(off_t offset, void* buffer, + size_t size); + +private: + int fFD; + uint32 fType; + const char* fAttribute; +}; + + class BufferDataReader : public DataReader { public: BufferDataReader(const void* data, size_t size);