From 48ce54dd26cfe8f5a633e1fcdc46dd054651b75a Mon Sep 17 00:00:00 2001 From: rofl0r Date: Fri, 10 Jan 2020 22:07:30 +0000 Subject: [PATCH] ByteArray: add support for 64bit-reads --- ByteArray.c | 13 +++++++++++++ ByteArray.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/ByteArray.c b/ByteArray.c index f89b2b4..ec915f9 100644 --- a/ByteArray.c +++ b/ByteArray.c @@ -22,6 +22,7 @@ void ByteArray_ctor(struct ByteArray* self) { self->readUnsignedShort = ByteArray_readUnsignedShort; self->readInt = ByteArray_readInt; self->readUnsignedInt = ByteArray_readUnsignedInt; + self->readUnsignedLongLong = ByteArray_readUnsignedLongLong; self->readBytes = ByteArray_readBytes; self->writeInt = ByteArray_writeInt; @@ -232,6 +233,18 @@ off_t ByteArray_bytesAvailable(struct ByteArray* self) { return 0; } +unsigned long long ByteArray_readUnsignedLongLong(struct ByteArray* self) { + union { + unsigned long long intval; + unsigned char charval[sizeof(unsigned long long)]; + } buf; + self->readMultiByte(self, (char*) buf.charval, 8); + if(self->endian != self->sys_endian) { + buf.intval = byteswap64(buf.intval); + } + return buf.intval; +} + unsigned int ByteArray_readUnsignedInt(struct ByteArray* self) { union { unsigned int intval; diff --git a/ByteArray.h b/ByteArray.h index c8f5e2a..8392426 100644 --- a/ByteArray.h +++ b/ByteArray.h @@ -42,6 +42,7 @@ struct ByteArray { int fd; } source; ssize_t (*readMultiByte)(struct ByteArray*, char*, size_t); + unsigned long long (*readUnsignedLongLong)(struct ByteArray*); unsigned int (*readUnsignedInt)(struct ByteArray*); signed int (*readInt)(struct ByteArray*); unsigned short (*readUnsignedShort)(struct ByteArray*); @@ -88,6 +89,7 @@ int ByteArray_set_position_rel(struct ByteArray* self, int rel); off_t ByteArray_bytesAvailable(struct ByteArray* self); ssize_t ByteArray_readMultiByte(struct ByteArray* self, char* buffer, size_t len); +unsigned long long ByteArray_readUnsignedLongLong(struct ByteArray* self); unsigned int ByteArray_readUnsignedInt(struct ByteArray* self); int ByteArray_readInt(struct ByteArray* self); unsigned short ByteArray_readUnsignedShort(struct ByteArray* self); -- 2.11.4.GIT