Browse code

No works on PPC

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

Nigel Horne authored on 2005/03/26 18:51:24
Showing 1 changed files
... ...
@@ -24,7 +24,7 @@
24 24
 #include "clamav-config.h"
25 25
 #endif
26 26
 
27
-static	char	const	rcsid[] = "$Id: tnef.c,v 1.9 2005/03/26 07:49:26 nigelhorne Exp $";
27
+static	char	const	rcsid[] = "$Id: tnef.c,v 1.10 2005/03/26 09:51:24 nigelhorne Exp $";
28 28
 
29 29
 #include <stdio.h>
30 30
 
... ...
@@ -56,9 +56,10 @@ static	int	tnef_attachment(FILE *fp, const char *dir, fileblob **fbref);
56 56
 #define host16(v)	(v)
57 57
 #define host32(v)	(v)
58 58
 #else
59
-#ifdef	__GNUC__
60
-#define	host16(v)	__bswap_16(x)
61
-#define	host32(v)	__bswap_32(x)
59
+#ifdef	C_LINUX
60
+#include <byteswap.h>
61
+#define	host16(v)	__bswap_16(v)
62
+#define	host32(v)	__bswap_32(v)
62 63
 #else
63 64
 #define	host16(v)	((v >> 8) | (v << 8))
64 65
 #define	host32(v)	((v >> 24) | ((v & 0x00FF0000) >> 8) | \
... ...
@@ -90,7 +91,7 @@ cli_tnef(const char *dir, int desc)
90 90
 		fclose(fp);
91 91
 		return CL_EIO;
92 92
 	}
93
-	if(i32 != TNEF_SIGNATURE) {
93
+	if(host32(i32) != TNEF_SIGNATURE) {
94 94
 		fclose(fp);
95 95
 		return CL_EFORMAT;
96 96
 	}
... ...
@@ -154,7 +155,9 @@ cli_tnef(const char *dir, int desc)
154 154
 		fb = NULL;
155 155
 	}
156 156
 	fclose(fp);
157
-	return CL_CLEAN;
157
+
158
+	cli_dbgmsg("cli_tnef: returning 0\n");
159
+	return CL_CLEAN;	/* we don't know if it's clean or not :-) */
158 160
 }
159 161
 
160 162
 static int
... ...
@@ -170,13 +173,13 @@ tnef_message(FILE *fp)
170 170
 	if(fread(&i32, sizeof(uint32_t), 1, fp) != 1)
171 171
 		return -1;
172 172
 
173
+	i32 = host32(i32);
173 174
 	tag = i32 & 0xFFFF;
174 175
 	type = (i32 & 0xFFFF0000) >> 16;
175 176
 
176 177
 	if(fread(&i32, sizeof(uint32_t), 1, fp) != 1)
177 178
 		return -1;
178
-
179
-	length = i32;
179
+	length = host32(i32);
180 180
 
181 181
 	cli_dbgmsg("message tag 0x%x, type 0x%x, length %u\n", tag, type, length);
182 182
 
... ...
@@ -194,6 +197,7 @@ tnef_message(FILE *fp)
194 194
 			/*assert(length == sizeof(uint32_t))*/
195 195
 			if(fread(&i32, sizeof(uint32_t), 1, fp) != 1)
196 196
 				return -1;
197
+			i32 = host32(i32);
197 198
 			cli_dbgmsg("TNEF version %d\n", i32);
198 199
 			break;
199 200
 		case attOEMCODEPAGE:
... ...
@@ -201,6 +205,7 @@ tnef_message(FILE *fp)
201 201
 			/*assert(length == sizeof(uint32_t))*/
202 202
 			if(fread(&i32, sizeof(uint32_t), 1, fp) != 1)
203 203
 				return -1;
204
+			i32 = host32(i32);
204 205
 			cli_dbgmsg("TNEF codepage %d\n", i32);
205 206
 			break;
206 207
 		case attDATEMODIFIED:
... ...
@@ -242,13 +247,13 @@ tnef_attachment(FILE *fp, const char *dir, fileblob **fbref)
242 242
 	if(fread(&i32, sizeof(uint32_t), 1, fp) != 1)
243 243
 		return -1;
244 244
 
245
+	i32 = host32(i32);
245 246
 	tag = i32 & 0xFFFF;
246 247
 	type = (i32 & 0xFFFF0000) >> 16;
247 248
 
248 249
 	if(fread(&i32, sizeof(uint32_t), 1, fp) != 1)
249 250
 		return -1;
250
-
251
-	length = i32;
251
+	length = host32(i32);
252 252
 
253 253
 	cli_dbgmsg("attachment tag 0x%x, type 0x%x, length %u\n", tag, type, length);
254 254
 
... ...
@@ -279,11 +284,21 @@ tnef_attachment(FILE *fp, const char *dir, fileblob **fbref)
279 279
 					return -1;
280 280
 			}
281 281
 			for(todo = length; todo; todo--) {
282
+#if WORDS_BIGENDIAN == 1
283
+				int c;
284
+				unsigned char c2;
285
+
286
+				if((c = fgetc(fp)) == EOF)
287
+					break;
288
+				c2 = (unsigned char)c;
289
+				fileblobAddData(*fbref, (const unsigned char *)&c2, 1);
290
+#else
282 291
 				int c;
283 292
 
284 293
 				if((c = fgetc(fp)) == EOF)
285 294
 					break;
286 295
 				fileblobAddData(*fbref, (const unsigned char *)&c, 1);
296
+#endif
287 297
 			}
288 298
 			break;
289 299
 		default: