Browse code

w32 patch

git-svn: trunk@2315

Tomasz Kojm authored on 2006/09/27 19:49:26
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed Sep 27 12:48:06 CEST 2006 (tk)
2
+----------------------------------
3
+  * shared/misc.c: apply w32 patch from NJH
4
+
1 5
 Wed Sep 27 12:20:38 CEST 2006 (tk)
2 6
 ----------------------------------
3 7
   * freshclam/dns.c: apply w32 support patch from Mark Pizzolato
... ...
@@ -23,22 +23,30 @@
23 23
 
24 24
 #include <stdio.h>
25 25
 #include <stdlib.h>
26
+#ifdef	HAVE_UNISTD_H
26 27
 #include <unistd.h>
28
+#endif
27 29
 #include <string.h>
28 30
 #include <time.h>
29 31
 #include <sys/types.h>
30 32
 #include <sys/stat.h>
33
+#ifndef	C_WINDOWS
31 34
 #include <dirent.h>
35
+#endif
32 36
 #include <fcntl.h>
33 37
 #include <ctype.h>
34 38
 #include <errno.h>
35 39
 
36
-#include "clamav.h"
37
-#include "cfgparser.h"
38
-#include "memory.h"
39
-#include "output.h"
40
+#include "shared/cfgparser.h"
41
+#include "shared/memory.h"
42
+#include "shared/output.h"
40 43
 
41
-#include "../libclamav/cvd.h"
44
+#include "libclamav/clamav.h"
45
+#include "libclamav/cvd.h"
46
+
47
+#ifndef	O_BINARY
48
+#define	O_BINARY	0
49
+#endif
42 50
 
43 51
 
44 52
 char *freshdbdir(void)
... ...
@@ -136,10 +144,10 @@ int filecopy(const char *src, const char *dest)
136 136
 	struct stat sb;
137 137
 
138 138
 
139
-    if((s = open(src, O_RDONLY)) == -1)
139
+    if((s = open(src, O_RDONLY|O_BINARY)) == -1)
140 140
 	return -1;
141 141
 
142
-    if((d = open(dest, O_CREAT|O_WRONLY|O_TRUNC)) == -1) {
142
+    if((d = open(dest, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY)) == -1) {
143 143
 	close(s);
144 144
 	return -1;
145 145
     }
... ...
@@ -177,13 +185,17 @@ int rmdirs(const char *dirname)
177 177
 	    }
178 178
 
179 179
 	    while((dent = readdir(dd))) {
180
-#if   (!defined(C_CYGWIN)) && (!defined(C_INTERIX))
180
+#if   (!defined(C_CYGWIN)) && (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
181 181
 		if(dent->d_ino)
182 182
 #endif
183 183
 		{
184 184
 		    if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
185 185
 			fname = mcalloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
186
+#ifdef	C_WINDOWS
187
+			sprintf(fname, "%s\\%s", dirname, dent->d_name);
188
+#else
186 189
 			sprintf(fname, "%s/%s", dirname, dent->d_name);
190
+#endif
187 191
 
188 192
 			/* stat the file */
189 193
 			if(lstat(fname, &statbuf) != -1) {
... ...
@@ -237,7 +249,7 @@ int dircopy(const char *src, const char *dest)
237 237
     }
238 238
 
239 239
     while((dent = readdir(dd))) {
240
-#if   (!defined(C_CYGWIN)) && (!defined(C_INTERIX))
240
+#if   (!defined(C_CYGWIN)) && (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
241 241
 	if(dent->d_ino)
242 242
 #endif
243 243
 	{
... ...
@@ -276,7 +288,7 @@ int cvd_unpack(const char *cvd, const char *destdir)
276 276
 	int fd;
277 277
 
278 278
 
279
-    if((fd = open(cvd, O_RDONLY)) == -1)
279
+    if((fd = open(cvd, O_RDONLY|O_BINARY)) == -1)
280 280
 	return -1;
281 281
 
282 282
     if(lseek(fd, 512, SEEK_SET) == -1) {
... ...
@@ -292,11 +304,12 @@ int cvd_unpack(const char *cvd, const char *destdir)
292 292
 
293 293
 void daemonize(void)
294 294
 {
295
-	int i;
296
-
297
-#ifdef C_OS2
295
+#if	defined(C_OS2) || defined(C_WINDOWS)
296
+	fputs("Background mode is not supported on your operating system\n", stderr);
298 297
     return;
299 298
 #else
299
+	int i;
300
+
300 301
 
301 302
     if((i = open("/dev/null", O_WRONLY)) == -1) {
302 303
 	for(i = 0; i <= 2; i++)