]> git.draconx.ca Git - liblbx.git/commitdiff
liblbx: Kill byteorder.h.
authorNick Bowler <nbowler@draconx.ca>
Thu, 4 Feb 2010 15:52:53 +0000 (10:52 -0500)
committerNick Bowler <nbowler@draconx.ca>
Mon, 8 Feb 2010 17:00:54 +0000 (12:00 -0500)
Convert the last users to the integer packing routines and get rid of
this hack.

configure.ac
src/Makefile.inc
src/byteorder.h [deleted file]
src/image.c

index eb4ff46ad35852b96fe770c4a4ccf0a24426492a..bf0a5f417e7ff9be122e784ec83bb042dd2e220a 100644 (file)
@@ -17,7 +17,6 @@ AC_PROG_CC_C99
 gl_EARLY
 
 AC_HEADER_ASSERT
-AC_C_BIGENDIAN
 
 LT_INIT
 
index 1c109f668ca7e7a412fd8649ed50c63c885fa496..a8772d183ffaf5777ff73593d1acbb3ef5fdc7be 100644 (file)
@@ -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 (file)
index 4cf2854..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef BYTEORDER_H_
-#define BYTEORDER_H_
-
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
-#include <stdint.h>
-
-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
index 4f335d07298c56e94d63be9156c1a7d6477f7920..888515b45293ad22b5815f4be9a8885fe3136f5e 100644 (file)
@@ -26,7 +26,6 @@
 #include <assert.h>
 #include <errno.h>
 
-#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;
        }