Browse code

Portability to Windows (visual studio)

git-svn: trunk@2121

Nigel Horne authored on 2006/07/26 00:09:45
Showing 6 changed files
... ...
@@ -16,19 +16,29 @@
16 16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 17
  *  MA 02110-1301, USA.
18 18
  */
19
-static	char	const	rcsid[] = "$Id: blob.c,v 1.51 2006/07/01 16:17:35 njh Exp $";
19
+static	char	const	rcsid[] = "$Id: blob.c,v 1.52 2006/07/25 15:09:45 njh Exp $";
20 20
 
21 21
 #if HAVE_CONFIG_H
22 22
 #include "clamav-config.h"
23 23
 #endif
24 24
 
25
+#ifdef	C_WINDOWS
26
+#include "stdafx.h"
27
+#endif
28
+
25 29
 #include <stdio.h>
26 30
 #include <stdlib.h>
27 31
 #include <string.h>
28 32
 #include <errno.h>
29 33
 #include <fcntl.h>
30 34
 
35
+#ifdef	C_WINDOWS
36
+#include <io.h>
37
+#endif
38
+
39
+#if	HAVE_SYS_PARAM_H
31 40
 #include <sys/param.h>	/* for NAME_MAX */
41
+#endif
32 42
 
33 43
 #ifdef	C_DARWIN
34 44
 #include <sys/types.h>
... ...
@@ -48,7 +58,7 @@ static	char	const	rcsid[] = "$Id: blob.c,v 1.51 2006/07/01 16:17:35 njh Exp $";
48 48
 
49 49
 #include <assert.h>
50 50
 
51
-#ifdef	C_MINGW
51
+#if	defined(C_MINGW) || defined(C_WINDOWS)
52 52
 #include <windows.h>
53 53
 #endif
54 54
 
... ...
@@ -226,7 +236,7 @@ blobGetData(const blob *b)
226 226
 	return(b->data);
227 227
 }
228 228
 
229
-unsigned long
229
+size_t
230 230
 blobGetDataSize(const blob *b)
231 231
 {
232 232
 	assert(b != NULL);
... ...
@@ -278,7 +288,7 @@ blobClose(blob *b)
278 278
 int
279 279
 blobcmp(const blob *b1, const blob *b2)
280 280
 {
281
-	unsigned long s1, s2;
281
+	size_t s1, s2;
282 282
 
283 283
 	assert(b1 != NULL);
284 284
 	assert(b2 != NULL);
... ...
@@ -409,8 +419,11 @@ fileblobSetFilename(fileblob *fb, const char *dir, const char *filename)
409 409
 	 * can return ETOOLONG even when the file name isn't too long
410 410
 	 */
411 411
 	snprintf(fullname, sizeof(fullname), "%s/clamavtmpXXXXXXXXXXXXX", dir);
412
+#elif	defined(C_WINDOWS)
413
+	sprintf_s(fullname, sizeof(fullname) - 1, "%s/%.*sXXXXXX", dir,
414
+		(int)(sizeof(fullname) - 9 - strlen(dir)), filename);
412 415
 #else
413
-	snprintf(fullname, sizeof(fullname) - 1, "%s/%.*sXXXXXX", dir,
416
+	sprintf(fullname, "%s/%.*sXXXXXX", dir,
414 417
 		(int)(sizeof(fullname) - 9 - strlen(dir)), filename);
415 418
 #endif
416 419
 
... ...
@@ -426,6 +439,18 @@ fileblobSetFilename(fileblob *fb, const char *dir, const char *filename)
426 426
 		cli_dbgmsg("fileblobSetFilename: retry as mkstemp(%s)\n", fullname);
427 427
 		fd = mkstemp(fullname);
428 428
 	}
429
+#elif	defined(C_WINDOWS)
430
+	cli_dbgmsg("fileblobSetFilename: _mktemp_s(%s)\n", fullname);
431
+	fd = _mktemp_s(fullname, sizeof(fullname));
432
+	if((fd < 0) && (errno == EINVAL)) {
433
+		/*
434
+		 * This happens with some Linux flavours when (mis)handling
435
+		 * filenames with foreign characters
436
+		 */
437
+		sprintf_s(fullname, sizeof(fullname), "%s/clamavtmpXXXXXXXXXXXXX", dir);
438
+		cli_dbgmsg("fileblobSetFilename: retry as mkstemp(%s)\n", fullname);
439
+		fd = _mktemp_s(fullname, sizeof(fullname));
440
+	}
429 441
 #else
430 442
 	cli_dbgmsg("fileblobSetFilename: mktemp(%s)\n", fullname);
431 443
 	(void)mktemp(fullname);
... ...
@@ -470,7 +495,7 @@ fileblobAddData(fileblob *fb, const unsigned char *data, size_t len)
470 470
 			return 0;
471 471
 		if(fb->ctx) {
472 472
 			if(fb->ctx->scanned)
473
-				*fb->ctx->scanned += len / CL_COUNT_PRECISION;
473
+				*fb->ctx->scanned += (unsigned long)len / CL_COUNT_PRECISION;
474 474
 
475 475
 			if((len > 5) && (cli_scanbuff((char *)data, len, fb->ctx->virname, fb->ctx->engine, 0) == CL_VIRUS)) {
476 476
 				cli_dbgmsg("fileblobAddData: found %s\n", *fb->ctx->virname);
... ...
@@ -26,8 +26,8 @@
26 26
 typedef struct blob {
27 27
 	char	*name;	/* filename */
28 28
 	unsigned	char	*data;	/* the stuff itself */
29
-	unsigned	long	len;	/* number of bytes of data so far */
30
-	unsigned	long	size;	/* number of bytes allocated to data so far */
29
+	size_t	len;	/* number of bytes of data so far */
30
+	size_t	size;	/* number of bytes allocated to data so far */
31 31
 	int	isClosed;
32 32
 #ifdef	CL_DEBUG
33 33
 	object_type	magic;	/* verify that this is a blob */
... ...
@@ -41,7 +41,7 @@ void	blobSetFilename(blob *b, const char *dir, const char *filename);
41 41
 const	char	*blobGetFilename(const blob *b);
42 42
 int	blobAddData(blob *b, const unsigned char *data, size_t len);
43 43
 unsigned char *blobGetData(const blob *b);
44
-unsigned	long	blobGetDataSize(const blob *b);
44
+size_t	blobGetDataSize(const blob *b);
45 45
 void	blobClose(blob *b);
46 46
 int	blobcmp(const blob *b1, const blob *b2);
47 47
 int	blobGrow(blob *b, size_t len);
... ...
@@ -16,7 +16,7 @@
16 16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 17
  *  MA 02110-1301, USA.
18 18
  */
19
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.324 2006/07/24 12:14:46 njh Exp $";
19
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.325 2006/07/25 15:09:45 njh Exp $";
20 20
 
21 21
 #if HAVE_CONFIG_H
22 22
 #include "clamav-config.h"
... ...
@@ -37,13 +37,19 @@ static	char	const	rcsid[] = "$Id: mbox.c,v 1.324 2006/07/24 12:14:46 njh Exp $";
37 37
 #include <errno.h>
38 38
 #include <assert.h>
39 39
 #include <string.h>
40
+#ifdef	HAVE_STRINGS_H
40 41
 #include <strings.h>
42
+#endif
41 43
 #include <ctype.h>
42 44
 #include <time.h>
43 45
 #include <fcntl.h>
46
+#ifdef	HAVE_SYS_PARAM_H
44 47
 #include <sys/param.h>
45
-#include <clamav.h>
48
+#endif
49
+#include "clamav.h"
50
+#ifndef	C_WINDOWS
46 51
 #include <dirent.h>
52
+#endif
47 53
 #include <limits.h>
48 54
 
49 55
 #if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
... ...
@@ -178,7 +184,9 @@ typedef enum	{ FALSE = 0, TRUE = 1 } bool;
178 178
  * more than one machine you must make sure that .../partial is on a shared
179 179
  * network filesystem
180 180
  */
181
+#ifndef	C_WINDOWS	/* TODO: when opendir() is done */
181 182
 #define	PARTIAL_DIR
183
+#endif
182 184
 
183 185
 /*#define	NEW_WORLD*/
184 186
 
... ...
@@ -3098,7 +3106,7 @@ strstrip(char *s)
3098 3098
 	if(s == (char *)NULL)
3099 3099
 		return(0);
3100 3100
 
3101
-	return(strip(s, strlen(s) + 1));
3101
+	return(strip(s, (int)strlen(s) + 1));
3102 3102
 }
3103 3103
 
3104 3104
 static int
... ...
@@ -4539,7 +4547,7 @@ next_is_folded_header(const text *t)
4539 4539
 		 *	Content-Transfer-Encoding: quoted-printable
4540 4540
 		 */
4541 4541
 		return FALSE;
4542
-	
4542
+
4543 4543
 	/*
4544 4544
 	 * Some are broken and don't fold headers lines
4545 4545
 	 * correctly as per section 2.2.3 of RFC2822.
... ...
@@ -16,7 +16,7 @@
16 16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 17
  *  MA 02110-1301, USA.
18 18
  */
19
-static	char	const	rcsid[] = "$Id: message.c,v 1.180 2006/07/18 14:56:04 njh Exp $";
19
+static	char	const	rcsid[] = "$Id: message.c,v 1.181 2006/07/25 15:09:45 njh Exp $";
20 20
 
21 21
 #if HAVE_CONFIG_H
22 22
 #include "clamav-config.h"
... ...
@@ -37,7 +37,9 @@ static	char	const	rcsid[] = "$Id: message.c,v 1.180 2006/07/18 14:56:04 njh Exp
37 37
 #endif
38 38
 #include <stdlib.h>
39 39
 #include <string.h>
40
+#ifdef	HAVE_STRINGS_H
40 41
 #include <strings.h>
42
+#endif
41 43
 #include <assert.h>
42 44
 #include <ctype.h>
43 45
 #include <stdio.h>
... ...
@@ -1028,7 +1030,7 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1028 1028
 
1029 1029
 	if((t_line = binhexBegin(m)) != NULL) {
1030 1030
 		unsigned char byte;
1031
-		unsigned long newlen = 0L, len, dataforklen, resourceforklen, l;
1031
+		size_t newlen = 0L, len, dataforklen, resourceforklen, l;
1032 1032
 		unsigned char *data;
1033 1033
 		char *ptr;
1034 1034
 		int bytenumber;
... ...
@@ -2506,8 +2508,8 @@ simil(const char *str1, const char *str2)
2506 2506
 {
2507 2507
 	LINK1 top = NULL;
2508 2508
 	unsigned int score = 0;
2509
-	unsigned int common, total, len1;
2510
-	unsigned int len2;
2509
+	size_t common, total;
2510
+	size_t len1, len2;
2511 2511
 	char ls1[MAX_PATTERN_SIZ], ls2[MAX_PATTERN_SIZ];
2512 2512
 	char *rs1 = NULL, *rs2 = NULL;
2513 2513
 	char *s1, *s2;
... ...
@@ -2541,7 +2543,7 @@ simil(const char *str1, const char *str2)
2541 2541
 		pop(&top, ls1);
2542 2542
 		common = compare(ls1, &rs1, ls2, &rs2);
2543 2543
 		if(common > 0) {
2544
-			score += common;
2544
+			score += (unsigned int)common;
2545 2545
 			len1 = strlen(ls1);
2546 2546
 			len2 = strlen(ls2);
2547 2547
 
... ...
@@ -31,7 +31,9 @@
31 31
 
32 32
 #include <stdlib.h>
33 33
 #include <string.h>
34
+#ifdef	HAVE_STRINGS_H
34 35
 #include <strings.h>
36
+#endif
35 37
 #include <assert.h>
36 38
 
37 39
 #include "table.h"
... ...
@@ -16,7 +16,7 @@
16 16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 17
  *  MA 02110-1301, USA.
18 18
  */
19
-static	char	const	rcsid[] = "$Id: uuencode.c,v 1.4 2006/05/19 11:02:12 njh Exp $";
19
+static	char	const	rcsid[] = "$Id: uuencode.c,v 1.5 2006/07/25 15:09:45 njh Exp $";
20 20
 
21 21
 #include "clamav.h"
22 22
 
... ...
@@ -24,13 +24,19 @@ static	char	const	rcsid[] = "$Id: uuencode.c,v 1.4 2006/05/19 11:02:12 njh Exp $
24 24
 #include "clamav-config.h"
25 25
 #endif
26 26
 
27
+#ifdef	HAVE_STRINGS_H
27 28
 #include <strings.h>
29
+#endif
28 30
 #include <stdio.h>
29 31
 #include <memory.h>
30 32
 #include <sys/stat.h>
31 33
 #include "others.h"
32 34
 #include "str.h"
33 35
 
36
+#ifdef	C_WINDOWS
37
+#include <io.h>
38
+#endif
39
+
34 40
 #include "mbox.h"
35 41
 #include "uuencode.h"
36 42
 
... ...
@@ -135,4 +141,3 @@ uudecodeFile(message *m, const char *firstline, const char *dir, FILE *fin)
135 135
 
136 136
 	return 1;
137 137
 }
138
-