Browse code

Start Endian support

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1439 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2005/03/26 08:00:48
Showing 1 changed files
... ...
@@ -20,7 +20,7 @@
20 20
 #include "clamav-config.h"
21 21
 #endif
22 22
 
23
-static	char	const	rcsid[] = "$Id: tnef.c,v 1.7 2005/03/25 21:58:01 nigelhorne Exp $";
23
+static	char	const	rcsid[] = "$Id: tnef.c,v 1.8 2005/03/25 23:00:48 nigelhorne Exp $";
24 24
 
25 25
 #include <stdio.h>
26 26
 
... ...
@@ -52,6 +52,20 @@ static	int	tnef_attachment(int desc, const char *dir, fileblob **fbref);
52 52
 #define	attTNEFVERSION	0x9006
53 53
 #define	attOEMCODEPAGE	0x9007
54 54
 
55
+#if WORDS_BIGENDIAN == 0
56
+#define host16(v)	(v)
57
+#define host32(v)	(v)
58
+#else
59
+#ifdef	__GNUC__
60
+#define	host16(v)	__bswap_16(x)
61
+#define	host32(v)	__bswap_32(x)
62
+#else
63
+#define	host16(v)	((v >> 8) | (v << 8))
64
+#define	host32(v)	((v >> 24) | ((v & 0x00FF0000) >> 8) | \
65
+				((v & 0x0000FF00) << 8) | (v << 24))
66
+#endif
67
+#endif
68
+
55 69
 /* FIXME: use stdio */
56 70
 /* FIXME: only works on little endian machines */
57 71
 int
... ...
@@ -68,13 +82,8 @@ cli_tnef(const char *dir, int desc)
68 68
 	if(cli_readn(desc, &i32, sizeof(uint32_t)) != sizeof(uint32_t))
69 69
 		return CL_EIO;
70 70
 
71
-#if	WORDS_BIGENDIAN == 0
72
-	/* little endian */
73
-	if(i32 != TNEF_SIGNATURE)
71
+	if(host32(i32) != host32(TNEF_SIGNATURE))
74 72
 		return CL_EFORMAT;
75
-#else
76
-	/* TODO */
77
-#endif
78 73
 
79 74
 	if(cli_readn(desc, &i16, sizeof(uint16_t)) != sizeof(uint16_t))
80 75
 		return CL_EIO;