diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Handle.cc | 54 | ||||
-rw-r--r-- | lib/Image.cc | 3 | ||||
-rw-r--r-- | lib/Input.cc | 7 |
3 files changed, 61 insertions, 3 deletions
diff --git a/lib/Handle.cc b/lib/Handle.cc index 030eb2c..d028c47 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -1,15 +1,19 @@ #include <stdio.h> #include <string.h> #include <errno.h> +#include <fcntl.h> +#include <byteswap.h> + #ifdef HAVE_CONFIG_H #include "config.h" #endif + #ifdef HAVE_UNISTD_H #include <unistd.h> #else #include <io.h> #endif -#include <fcntl.h> + #include "Handle.h" #include "gettext.h" @@ -330,6 +334,54 @@ off_t Handle::seek(off_t offset, int whence) throw(GeneralException) { } } +Uint8 Handle::readU8() { + Uint8 r; + read(&r, 1); + return r; +} + +Uint16 Handle::readU16() { + Uint16 r; + read(&r, 2); +#ifdef WORDS_BIGENDIAN + return bswap_16(r); +#else + return r; +#endif +} + +Uint32 Handle::readU32() { + Uint32 r; + read(&r, 4); +#ifdef WORDS_BIGENDIAN + return bswap_32(r); +#else + return r; +#endif +} + +void Handle::writeU8(Uint8 v) { + write(&v, 1); +} + +void Handle::writeU16(Uint16 v) { +#ifdef WORDS_BIGENDIAN + Uint16 t = bswap_16(v); + write(&t, 2); +#else + write(&v, 2); +#endif +} + +void Handle::writeU32(Uint32 v) { +#ifdef WORDS_BIGENDIAN + Uint32 t = bswap_32(v); + write(&t, 4); +#else + write(&v, 4); +#endif +} + void copy(Handle * s, Handle * d, ssize_t size) { long i; unsigned char c; diff --git a/lib/Image.cc b/lib/Image.cc index a0ece1b..6b698ae 100644 --- a/lib/Image.cc +++ b/lib/Image.cc @@ -44,6 +44,9 @@ void Image::SetPixel(unsigned int px, unsigned int py, Color c) { #ifndef WORDS_BIGENDIAN #define WORDS_BIGENDIAN 0 +#else +#undef WORDS_BIGENDIAN +#define WORDS_BIGENDIAN 1 #endif bool Image::Prepare(unsigned int f) { diff --git a/lib/Input.cc b/lib/Input.cc index 4648d91..60e17c9 100644 --- a/lib/Input.cc +++ b/lib/Input.cc @@ -4,14 +4,17 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> + #ifdef HAVE_CONFIG_H #include "config.h" #endif + #ifdef HAVE_UNISTD_H #include <unistd.h> #else #include <io.h> #endif + #include "Input.h" #include "Exceptions.h" #include "gettext.h" @@ -89,7 +92,7 @@ Input::Input(const String & no) throw (GeneralException) : } else { // size = results.size; seek(results.ptr, SEEK_SET); - read(&size, 4); + size = readU32(); date_modif = 0; SetZ(); fromarchive = true; @@ -201,7 +204,7 @@ Archive::Archive(const String & fname, int atype) throw (GeneralException) : archive.read(buffer, len); buffer[len] = 0; ifname = buffer; - archive.read(&size, 4); + size = archive.readU32(); archive.read(buffer, 1); #ifdef DEBUG std::cerr << "Adding file `" << ifname << "' to node `" << p->name << "'\n"; |