From: kramm Date: Thu, 13 Dec 2001 09:54:59 +0000 (+0000) Subject: added byte order handling X-Git-Tag: release-0-2-1~32 X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=commitdiff_plain;h=5591193a032de5fe7b6f61954c19b51a3709507e added byte order handling --- diff --git a/lib/rfxswf.c b/lib/rfxswf.c index 7754ba9..5f49939 100644 --- a/lib/rfxswf.c +++ b/lib/rfxswf.c @@ -545,12 +545,15 @@ TAG * RFXSWF_ReadTag(int handle,TAG * prev) int id; if (read(handle,&raw,2)!=2) return NULL; + raw = SWAP16(raw); len = raw&0x3f; id = raw>>6; if (len==0x3f) - { if (read(handle,&len,4)!=4) return NULL; + { + if (read(handle,&len,4)!=4) return NULL; + len = SWAP32(len); } if (id==ST_DEFINESPRITE) len = 2*sizeof(U16); @@ -610,7 +613,7 @@ int RFXSWF_WriteTag(int handle,TAG * t) if (handle>=0) { if (short_tag) - { raw[0] = len|((t->id&0x3ff)<<6); + { raw[0] = SWAP16(len|((t->id&0x3ff)<<6)); if (write(handle,raw,2)!=2) { #ifdef DEBUG_RFXSWF @@ -620,13 +623,21 @@ int RFXSWF_WriteTag(int handle,TAG * t) } } else - { raw[0] = (t->id<<6)|0x3f; - raw[1] = (U16)(len&0xffff); - raw[2] = (U16)(len>>16); - if (write(handle,raw,6)!=6) + { + raw[0] = SWAP16((t->id<<6)|0x3f); + if (write(handle,raw,2)!=2) + { +#ifdef DEBUG_RFXSWF + fprintf(stderr,"WriteTag() failed: Long Header (1).\n"); +#endif + return -1; + } + + len = SWAP32(len); + if (write(handle,&len,4)!=4) { #ifdef DEBUG_RFXSWF - fprintf(stderr,"WriteTag() failed: Long Header.\n"); + fprintf(stderr,"WriteTag() failed: Long Header (2).\n"); #endif return -1; } diff --git a/lib/rfxswf.h b/lib/rfxswf.h index 016f8e3..81ccf9f 100644 --- a/lib/rfxswf.h +++ b/lib/rfxswf.h @@ -29,6 +29,14 @@ #define FALSE (0) #endif +#ifdef WORDS_BIGENDIAN +#define SWAP16(s) ((U16) ((U8*)&s)[0] | ((U16) ((U8*)&s)[1] << 8)) +#define SWAP32(s) ((U32) ((U8*)&s)[0] | ((U32) ((U8*)&s)[1] << 8) | ((U32) ((U8*)&s)[2] << 16) | ((U32) ((U8*)&s)[3] << 24)) +#else +#define SWAP16(x) x +#define SWAP32(x) x +#endif + // SWF Types typedef unsigned long U32;