From 701ebeb36579550f6049112263560f6dc9a94d96 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 4 Feb 2010 10:52:53 -0500 Subject: [PATCH] liblbx: Kill byteorder.h. Convert the last users to the integer packing routines and get rid of this hack. --- configure.ac | 1 - src/Makefile.inc | 2 +- src/byteorder.h | 36 ------------------------------------ src/image.c | 31 ++++++++++++++++--------------- 4 files changed, 17 insertions(+), 53 deletions(-) delete mode 100644 src/byteorder.h diff --git a/configure.ac b/configure.ac index eb4ff46..bf0a5f4 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,6 @@ AC_PROG_CC_C99 gl_EARLY AC_HEADER_ASSERT -AC_C_BIGENDIAN LT_INIT diff --git a/src/Makefile.inc b/src/Makefile.inc index 1c109f6..a8772d1 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -7,7 +7,7 @@ lbxdir = $(includedir)/lbx lbx_HEADERS = src/lbx.h src/image.h -noinst_HEADERS += src/byteorder.h src/misc.h src/tools.h src/pack.h +noinst_HEADERS += src/misc.h src/tools.h src/pack.h lib_LTLIBRARIES += liblbx.la liblbx_la_SOURCES = src/misc.c src/lbx.c src/fops.c src/image.c src/pack.c diff --git a/src/byteorder.h b/src/byteorder.h deleted file mode 100644 index 4cf2854..0000000 --- a/src/byteorder.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef BYTEORDER_H_ -#define BYTEORDER_H_ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include - -static inline uint16_t _flip16(uint16_t val) -{ - uint16_t hostval; - int i; - - for (i = 0; i < sizeof val; i++) - ((uint8_t *)&hostval)[i] = ((uint8_t *)&val)[sizeof val - i]; -} - -static inline uint32_t _flip32(uint32_t val) -{ - uint32_t hostval; - int i; - - for (i = 0; i < sizeof val; i++) - ((uint8_t *)&hostval)[i] = ((uint8_t *)&val)[sizeof val - i]; -} - -#ifdef WORDS_BIGENDIAN -# define letohs(x) _flip16(x) -# define letohl(x) _flip32(x) -#else -# define letohs(x) ((uint16_t)(x)) -# define letohl(x) ((uint16_t)(x)) -#endif - -#endif diff --git a/src/image.c b/src/image.c index 4f335d0..888515b 100644 --- a/src/image.c +++ b/src/image.c @@ -26,7 +26,6 @@ #include #include -#include "byteorder.h" #include "pack.h" #include "misc.h" #include "lbx.h" @@ -155,16 +154,18 @@ struct lbx_image *lbximg_fopen(FILE *f) static int _lbx_drawrow(int first, struct lbx_image *img) { - uint16_t type, yval, count, xval; + unsigned short type, count, yval, xval; + unsigned char buf[4]; unsigned char *pos; - unsigned char abyss; size_t rc; assert(img->framedata); assert(img->mask); - if (fread(&type, sizeof type, 1, img->f) != 1) goto readerr; - type = letohs(type); img->foff += sizeof type; + if (fread(buf, 1, sizeof buf, img->f) != sizeof buf) + goto readerr; + img->foff += 4; + type = unpack_16_le(buf+0); if (first) { img->currentx = 0; @@ -173,14 +174,16 @@ static int _lbx_drawrow(int first, struct lbx_image *img) } if (type == 0) { - if (fread(&yval, sizeof yval, 1, img->f) != 1) goto readerr; - yval = letohs(yval); img->foff += sizeof yval; + yval = unpack_16_le(buf+2); if (yval == 1000) return 1; - if (fread(&count, sizeof count, 1, img->f) != 1) goto readerr; - count = letohs(count); img->foff += sizeof count; - if (fread(&xval, sizeof xval, 1, img->f) != 1) goto readerr; - xval = letohs(xval); img->foff += sizeof xval; + + if (fread(buf, 1, sizeof buf, img->f) != sizeof buf) + goto readerr; + img->foff += 4; + count = unpack_16_le(buf+0); + + xval = unpack_16_le(buf+2); if (xval == 1000) return 1; @@ -193,8 +196,7 @@ static int _lbx_drawrow(int first, struct lbx_image *img) img->currenty += yval; img->currentx = xval; } else { - if (fread(&xval, sizeof xval, 1, img->f) != 1) goto readerr; - xval = letohs(xval); img->foff += sizeof xval; + xval = unpack_16_le(buf+2); if (img->width - img->currentx <= xval) { lbx_errno = LBX_EFORMAT; @@ -203,7 +205,6 @@ static int _lbx_drawrow(int first, struct lbx_image *img) img->currentx += xval; count = type; - } if (count > img->width - img->currentx) { @@ -222,7 +223,7 @@ static int _lbx_drawrow(int first, struct lbx_image *img) goto readerr; if (count % 2) { - if (fread(&abyss, 1, 1, img->f) != 1) + if (fread(buf, 1, 1, img->f) != 1) goto readerr; img->foff += 1; } -- 2.43.2