Browse code

libclamunrar_iface, clamd, freshclam: merge win32 patches from NJH (bb#802)

git-svn: trunk@3872

Tomasz Kojm authored on 2008/05/30 19:27:24
Showing 8 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri May 30 11:40:56 CEST 2008 (tk)
2
+----------------------------------
3
+  * libclamunrar_iface, clamd, freshclam: merge win32 patches from NJH (bb#802)
4
+
1 5
 Wed May 28 03:49:55 CEST 2008 (acab)
2 6
 ------------------------------------
3 7
   * docs/man: typo
... ...
@@ -35,7 +35,9 @@
35 35
 #include <sys/stat.h>
36 36
 #include <fcntl.h>
37 37
 #include <time.h>
38
-#ifndef	C_WINDOWS
38
+#ifdef C_WINDOWS
39
+#include <direct.h>	/* for chdir */
40
+#else
39 41
 #include <pwd.h>
40 42
 #include <grp.h>
41 43
 #endif
... ...
@@ -65,6 +67,9 @@
65 65
 #include "others.h"
66 66
 #include "shared.h"
67 67
 
68
+#ifndef C_WINDOWS
69
+#define	closesocket(s)	close(s)
70
+#endif
68 71
 
69 72
 short debug_mode = 0, logok = 0;
70 73
 short foreground = 0;
... ...
@@ -86,7 +91,9 @@ int main(int argc, char **argv)
86 86
 {
87 87
 	struct cfgstruct *copt;
88 88
 	const struct cfgstruct *cpt;
89
+#ifndef	C_WINDOWS
89 90
         struct passwd *user = NULL;
91
+#endif
90 92
 	time_t currtime;
91 93
 	struct cl_engine *engine = NULL;
92 94
 	const char *dbdir, *cfgfile;
... ...
@@ -281,8 +288,10 @@ int main(int argc, char **argv)
281 281
 
282 282
     logg("#clamd daemon "VERSION" (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")\n");
283 283
 
284
+#ifndef C_WINDOWS
284 285
     if(user)
285 286
 	logg("#Running as user %s (UID %u, GID %u)\n", user->pw_name, user->pw_uid, user->pw_gid);
287
+#endif
286 288
 
287 289
     if(logg_size)
288 290
 	logg("#Log file size limited to %d bytes.\n", logg_size);
... ...
@@ -366,7 +375,7 @@ int main(int argc, char **argv)
366 366
 	    logg_close();
367 367
 	    freecfg(copt);
368 368
 	    if(tcpsock)
369
-		close(lsockets[0]);
369
+		closesocket(lsockets[0]);
370 370
 	    return 1;
371 371
 	}
372 372
 	nlsockets++;
... ...
@@ -479,13 +479,13 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en
479 479
     if(!bound && !portscan) {
480 480
 	logg("!ScanStream: Can't find any free port.\n");
481 481
 	mdprintf(odesc, "Can't find any free port. ERROR\n");
482
-	close(sockfd);
482
+	closesocket(sockfd);
483 483
 	return -1;
484 484
     } else {
485 485
 	listen(sockfd, 1);
486 486
 	if(mdprintf(odesc, "PORT %u\n", port) <= 0) {
487 487
 	    logg("!ScanStream: error transmitting port.\n");
488
-	    close(sockfd);
488
+	    closesocket(sockfd);
489 489
 	    return -1;
490 490
 	}
491 491
     }
... ...
@@ -494,17 +494,17 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en
494 494
 	case 0: /* timeout */
495 495
 	    mdprintf(odesc, "Accept timeout. ERROR\n");
496 496
 	    logg("!ScanStream %u: accept timeout.\n", port);
497
-	    close(sockfd);
497
+	    closesocket(sockfd);
498 498
 	    return -1;
499 499
 	case -1:
500 500
 	    mdprintf(odesc, "Accept poll. ERROR\n");
501 501
 	    logg("!ScanStream %u: accept poll failed.\n", port);
502
-	    close(sockfd);
502
+	    closesocket(sockfd);
503 503
 	    return -1;
504 504
     }
505 505
 
506 506
     if((acceptd = accept(sockfd, NULL, NULL)) == -1) {
507
-	close(sockfd);
507
+	closesocket(sockfd);
508 508
 	mdprintf(odesc, "accept() ERROR\n");
509 509
 	logg("!ScanStream %u: accept() failed.\n", port);
510 510
 	return -1;
... ...
@@ -514,8 +514,8 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en
514 514
 
515 515
     if(cli_gentempfd(NULL, &tmpname, &tmpd)) {
516 516
 	shutdown(sockfd, 2);
517
-	close(sockfd);
518
-	close(acceptd);
517
+	closesocket(sockfd);
518
+	closesocket(acceptd);
519 519
 	mdprintf(odesc, "cli_gentempfd() failed. ERROR\n");
520 520
 	logg("!ScanStream %u: Can't create temporary file.\n", port);
521 521
 	return -1;
... ...
@@ -588,7 +588,7 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigne
588 588
 		client_conn->socketds = socketds;
589 589
 		client_conn->nsockets = nsockets;
590 590
 		if (!thrmgr_dispatch(thr_pool, client_conn)) {
591
-		    close(client_conn->sd);
591
+		    closesocket(client_conn->sd);
592 592
 		    free(client_conn);
593 593
 		    logg("!thread dispatch failed\n");
594 594
 		}
... ...
@@ -596,9 +596,12 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigne
596 596
 
597 597
 	pthread_mutex_lock(&exit_mutex);
598 598
 	if(progexit) {
599
-	    if (new_sd >= 0) {
599
+#ifdef C_WINDOWS
600
+	    closesocket(new_sd);
601
+#else
602
+  	    if(new_sd >= 0)
600 603
 		close(new_sd);
601
-	    }
604
+#endif
602 605
 	    pthread_mutex_unlock(&exit_mutex);
603 606
 	    break;
604 607
 	}
... ...
@@ -622,8 +625,12 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigne
622 622
 	    engine = reload_db(engine, dboptions, copt, FALSE, &ret);
623 623
 	    if(ret) {
624 624
 		logg("Terminating because of a fatal error.\n");
625
+#ifdef C_WINDOWS
626
+		closesocket(new_sd);
627
+#else
625 628
 		if(new_sd >= 0)
626 629
 		    close(new_sd);
630
+#endif
627 631
 		break;
628 632
 	    }
629 633
 	    pthread_mutex_lock(&reload_mutex);
... ...
@@ -51,6 +51,10 @@
51 51
 #include "server.h"
52 52
 #include "tcpserver.h"
53 53
 
54
+#ifndef	C_WINDOWS
55
+#define	closesocket(s)	close(s)
56
+#endif
57
+
54 58
 int tcpserver(const struct cfgstruct *copt)
55 59
 {
56 60
 	struct sockaddr_in server;
... ...
@@ -87,7 +91,7 @@ int tcpserver(const struct cfgstruct *copt)
87 87
     if(bind(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) == -1) {
88 88
 	estr = strerror(errno);
89 89
 	logg("!TCP: bind() error: %s\n", estr);
90
-	close(sockfd);
90
+	closesocket(sockfd);
91 91
 	return -1;
92 92
     } else {
93 93
 	if(taddr->enabled)
... ...
@@ -102,7 +106,7 @@ int tcpserver(const struct cfgstruct *copt)
102 102
     if(listen(sockfd, backlog) == -1) {
103 103
 	estr = strerror(errno);
104 104
 	logg("!TCP: listen() error: %s\n", estr);
105
-	close(sockfd);
105
+	closesocket(sockfd);
106 106
 	return -1;
107 107
     }
108 108
 
... ...
@@ -1,442 +1,3 @@
1
-*** /home/njh/src/clamav-devel/trunk/./clamscan/clamscan.c	2008-02-15 09:45:55.000000000 +0000
2
-***************
3
-*** 260,265 ****
4
-  	return 72;
5
-      }
6
-  #endif
7
-+ #ifdef        _DEBUG
8
-+ 	_CrtDumpMemoryLeaks();
9
-+ #endif
10
-  
11
-      return ret;
12
-  }
13
-*** /home/njh/src/clamav-devel/trunk/./clamscan/manager.h	2007-12-06 18:32:26.000000000 +0000
14
-***************
15
-*** 34,37 ****
16
-  
17
-  int scanfile(const char *filename, struct cl_engine *engine, const struct passwd *user, const struct optstruct *opt, const struct cl_limits *limits, unsigned int options);
18
-  
19
-+ #ifdef	_DEBUG
20
-+ /* breaks mspack/qtmd.c :-( */
21
-+ #define	free(p)	_free_dbg(p, _NORMAL_BLOCK)
22
-+ #endif
23
-+ 
24
-  #endif
25
-*** /home/njh/src/clamav-devel/trunk/./clamscan/others.c	2008-02-19 14:17:17.000000000 +0000
26
-***************
27
-*** 77,83 ****
28
-  /* FIXME: Handle users correctly */
29
-  int checkaccess(const char *path, const char *username, int mode)
30
-  {
31
-!     return !_access(path, mode);
32
-  }
33
-  #else
34
-  int checkaccess(const char *path, const char *username, int mode)
35
-  /* FIXME: Handle users correctly */
36
-  int checkaccess(const char *path, const char *username, int mode)
37
-  {
38
-! 	return _access(path, mode) == 0;
39
-  }
40
-  #else
41
-  int checkaccess(const char *path, const char *username, int mode)
42
-*** /home/njh/src/clamav-devel/trunk/./freshclam/manager.c	2008-02-25 15:41:07.000000000 +0000
43
-***************
44
-*** 49,55 ****
45
-  #include <time.h>
46
-  #include <fcntl.h>
47
-  #include <sys/stat.h>
48
-+ #ifndef	C_WINDOWS
49
-  #include <dirent.h>
50
-+ #endif
51
-  #include <errno.h>
52
-  #include <zlib.h>
53
-  
54
-***************
55
-*** 212,218 ****
56
-  		break;
57
-  	}
58
-          logg("%cCan't get information about %s: %s\n", logerr ? '!' : '^', hostpt, herr);
59
-! 	close(socketfd);
60
-  	return -1;
61
-      }
62
-  
63
-  		break;
64
-  	}
65
-          logg("%cCan't get information about %s: %s\n", logerr ? '!' : '^', hostpt, herr);
66
-! 	closesocket(socketfd);
67
-  	return -1;
68
-      }
69
-  
70
-***************
71
-*** 244,250 ****
72
-  	if(connect(socketfd, (struct sockaddr *) &name, sizeof(struct sockaddr_in)) == -1) {
73
-  #endif
74
-  	    logg("Can't connect to port %d of host %s (IP: %s)\n", port, hostpt, ipaddr);
75
-! 	    close(socketfd);
76
-  	    if((socketfd = getclientsock(localip)) == -1)
77
-  		return -1;
78
-  
79
-  	if(connect(socketfd, (struct sockaddr *) &name, sizeof(struct sockaddr_in)) == -1) {
80
-  #endif
81
-  	    logg("Can't connect to port %d of host %s (IP: %s)\n", port, hostpt, ipaddr);
82
-! 	    closesocket(socketfd);
83
-  	    if((socketfd = getclientsock(localip)) == -1)
84
-  		return -1;
85
-  
86
-***************
87
-*** 255,261 ****
88
-  	}
89
-      }
90
-  
91
-!     close(socketfd);
92
-      return -2;
93
-  }
94
-  
95
-  	}
96
-      }
97
-  
98
-!     closesocket(socketfd);
99
-      return -2;
100
-  }
101
-  
102
-***************
103
-*** 918,924 ****
104
-      }
105
-  
106
-      while((dent = readdir(dir))) {
107
-! #ifndef C_INTERIX
108
-  	if(dent->d_ino)
109
-  #endif
110
-  	{
111
-      }
112
-  
113
-      while((dent = readdir(dir))) {
114
-! #if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS))
115
-  	if(dent->d_ino)
116
-  #endif
117
-  	{
118
-*** /home/njh/src/clamav-devel/trunk/./freshclam/freshclam.c	2008-01-23 11:58:35.000000000 +0000
119
-***************
120
-*** 419,424 ****
121
-  #endif
122
-  
123
-      /* change the current working directory */
124
-+     if(opt_check(opt, "datadir"))
125
-+ 	newdir = opt_arg(opt, "datadir");
126
-+     else
127
-+ 	newdir = cfgopt(copt, "DatabaseDirectory")->strarg;
128
-+ 
129
-      if(chdir(newdir)) {
130
-  	logg("Can't change dir to %s\n", newdir);
131
-  	opt_free(opt);
132
-***************
133
-*** 493,499 ****
134
-  		opt_free(opt);
135
-  		freecfg(copt);
136
-  		return 70; /* FIXME */
137
-! 	    }
138
-              foreground = 0;
139
-  	    mprintf_disabled = 1;
140
-          }
141
-  		opt_free(opt);
142
-  		freecfg(copt);
143
-  		return 70; /* FIXME */
144
-! 	   }
145
-              foreground = 0;
146
-  	    mprintf_disabled = 1;
147
-          }
148
-*** /home/njh/src/clamav-devel/trunk/./clamd/scanner.c	2008-02-15 09:45:21.000000000 +0000
149
-***************
150
-*** 440,452 ****
151
-      if(!bound && !portscan) {
152
-  	logg("!ScanStream: Can't find any free port.\n");
153
-  	mdprintf(odesc, "Can't find any free port. ERROR\n");
154
-! 	close(sockfd);
155
-  	return -1;
156
-      } else {
157
-  	listen(sockfd, 1);
158
-  	if(mdprintf(odesc, "PORT %u\n", port) <= 0) {
159
-  	    logg("!ScanStream: error transmitting port.\n");
160
-! 	    close(sockfd);
161
-  	    return -1;
162
-  	}
163
-      }
164
-      if(!bound && !portscan) {
165
-  	logg("!ScanStream: Can't find any free port.\n");
166
-  	mdprintf(odesc, "Can't find any free port. ERROR\n");
167
-! 	closesocket(sockfd);
168
-  	return -1;
169
-      } else {
170
-  	listen(sockfd, 1);
171
-  	if(mdprintf(odesc, "PORT %u\n", port) <= 0) {
172
-  	    logg("!ScanStream: error transmitting port.\n");
173
-! 	    closesocket(sockfd);
174
-  	    return -1;
175
-  	}
176
-      }
177
-***************
178
-*** 455,471 ****
179
-  	case 0: /* timeout */
180
-  	    mdprintf(odesc, "Accept timeout. ERROR\n");
181
-  	    logg("!ScanStream %u: accept timeout.\n", port);
182
-! 	    close(sockfd);
183
-  	    return -1;
184
-  	case -1:
185
-  	    mdprintf(odesc, "Accept poll. ERROR\n");
186
-  	    logg("!ScanStream %u: accept poll failed.\n", port);
187
-! 	    close(sockfd);
188
-  	    return -1;
189
-      }
190
-  
191
-      if((acceptd = accept(sockfd, NULL, NULL)) == -1) {
192
-! 	close(sockfd);
193
-  	mdprintf(odesc, "accept() ERROR\n");
194
-  	logg("!ScanStream %u: accept() failed.\n", port);
195
-  	return -1;
196
-  	case 0: /* timeout */
197
-  	    mdprintf(odesc, "Accept timeout. ERROR\n");
198
-  	    logg("!ScanStream %u: accept timeout.\n", port);
199
-! 	    closesocket(sockfd);
200
-  	    return -1;
201
-  	case -1:
202
-  	    mdprintf(odesc, "Accept poll. ERROR\n");
203
-  	    logg("!ScanStream %u: accept poll failed.\n", port);
204
-! 	    closesocket(sockfd);
205
-  	    return -1;
206
-      }
207
-  
208
-      if((acceptd = accept(sockfd, NULL, NULL)) == -1) {
209
-! 	closesocket(sockfd);
210
-  	mdprintf(odesc, "accept() ERROR\n");
211
-  	logg("!ScanStream %u: accept() failed.\n", port);
212
-  	return -1;
213
-***************
214
-*** 475,482 ****
215
-  
216
-      if(cli_gentempfd(NULL, &tmpname, &tmpd)) {
217
-  	shutdown(sockfd, 2);
218
-! 	close(sockfd);
219
-! 	close(acceptd);
220
-  	mdprintf(odesc, "cli_gentempfd() failed. ERROR\n");
221
-  	logg("!ScanStream %u: Can't create temporary file.\n", port);
222
-  	return -1;
223
-  
224
-      if(cli_gentempfd(NULL, &tmpname, &tmpd)) {
225
-  	shutdown(sockfd, 2);
226
-! 	closesocket(sockfd);
227
-! 	closesocket(acceptd);
228
-  	mdprintf(odesc, "cli_gentempfd() failed. ERROR\n");
229
-  	logg("!ScanStream %u: Can't create temporary file.\n", port);
230
-  	return -1;
231
-*** /home/njh/src/clamav-devel/trunk/./clamd/clamd.c	2008-02-18 16:35:00.000000000 +0000
232
-***************
233
-*** 35,41 ****
234
-  #include <sys/stat.h>
235
-  #include <fcntl.h>
236
-  #include <time.h>
237
-! #ifndef	C_WINDOWS
238
-  #include <pwd.h>
239
-  #include <grp.h>
240
-  #endif
241
-  #include <sys/stat.h>
242
-  #include <fcntl.h>
243
-  #include <time.h>
244
-! #ifdef	C_WINDOWS
245
-! #include <direct.h>	/* for chdir */
246
-! #else
247
-  #include <pwd.h>
248
-  #include <grp.h>
249
-  #endif
250
-***************
251
-*** 65,70 ****
252
-  #include "others.h"
253
-  #include "shared.h"
254
-  
255
-+ #ifndef	C_WINDOWS
256
-+ #define	closesocket(s)	close(s)
257
-+ #endif
258
-  
259
-  short debug_mode = 0, logok = 0;
260
-  short foreground = 0;
261
-***************
262
-*** 86,92 ****
263
-  {
264
-  	struct cfgstruct *copt;
265
-  	const struct cfgstruct *cpt;
266
-+ #ifndef	C_WINDOWS
267
-          struct passwd *user = NULL;
268
-+ #endif
269
-  	time_t currtime;
270
-  	struct cl_engine *engine = NULL;
271
-  	const char *dbdir, *cfgfile;
272
-***************
273
-*** 281,288 ****
274
-  
275
-      logg("#clamd daemon "VERSION" (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")\n");
276
-  
277
-+ #ifndef	C_WINDOWS
278
-      if(user)
279
-  	logg("#Running as user %s (UID %u, GID %u)\n", user->pw_name, user->pw_uid, user->pw_gid);
280
-+ #endif
281
-  
282
-      if(logg_size)
283
-  	logg("#Log file size limited to %d bytes.\n", logg_size);
284
-***************
285
-*** 366,372 ****
286
-  	    logg_close();
287
-  	    freecfg(copt);
288
-  	    if(tcpsock)
289
-! 		close(lsockets[0]);
290
-  	    return 1;
291
-  	}
292
-  	nlsockets++;
293
-  	    logg_close();
294
-  	    freecfg(copt);
295
-  	    if(tcpsock)
296
-! 		closesocket(lsockets[0]);
297
-  	    return 1;
298
-  	}
299
-  	nlsockets++;
300
-*** /home/njh/src/clamav-devel/trunk/./clamd/server-th.c	2008-02-25 15:44:06.000000000 +0000
301
-***************
302
-*** 573,579 ****
303
-  		client_conn->socketds = socketds;
304
-  		client_conn->nsockets = nsockets;
305
-  		if (!thrmgr_dispatch(thr_pool, client_conn)) {
306
-! 		    close(client_conn->sd);
307
-  		    free(client_conn);
308
-  		    logg("!thread dispatch failed\n");
309
-  		}
310
-  		client_conn->socketds = socketds;
311
-  		client_conn->nsockets = nsockets;
312
-  		if (!thrmgr_dispatch(thr_pool, client_conn)) {
313
-! 		    closesocket(client_conn->sd);
314
-  		    free(client_conn);
315
-  		    logg("!thread dispatch failed\n");
316
-  		}
317
-***************
318
-*** 581,589 ****
319
-  
320
-  	pthread_mutex_lock(&exit_mutex);
321
-  	if(progexit) {
322
-! 	    if (new_sd >= 0) {
323
-! 		close(new_sd);
324
-! 	    }
325
-  	    pthread_mutex_unlock(&exit_mutex);
326
-  	    break;
327
-  	}
328
-  
329
-  	pthread_mutex_lock(&exit_mutex);
330
-  	if(progexit) {
331
-! #ifdef	C_WINDOWS
332
-! 	    closesocket(new_sd);
333
-! #else
334
-!   	    if (new_sd >= 0)
335
-! 		closesocket(new_sd);
336
-! #endif
337
-  	    pthread_mutex_unlock(&exit_mutex);
338
-  	    break;
339
-  	}
340
-***************
341
-*** 607,614 ****
342
-  	    engine = reload_db(engine, dboptions, copt, FALSE, &ret);
343
-  	    if(ret) {
344
-  		logg("Terminating because of a fatal error.\n");
345
-! 		if(new_sd >= 0)
346
-! 		    close(new_sd);
347
-  		break;
348
-  	    }
349
-  	    pthread_mutex_lock(&reload_mutex);
350
-  	    engine = reload_db(engine, dboptions, copt, FALSE, &ret);
351
-  	    if(ret) {
352
-  		logg("Terminating because of a fatal error.\n");
353
-! #ifdef	C_WINDOWS
354
-! 		closesocket(new_sd);
355
-! #else
356
-! 		if (new_sd >= 0)
357
-! 			closesocket(new_sd);
358
-! #endif
359
-  		break;
360
-  	    }
361
-  	    pthread_mutex_lock(&reload_mutex);
362
-*** /home/njh/src/clamav-devel/trunk/./clamd/tcpserver.c	2008-02-18 16:35:00.000000000 +0000
363
-***************
364
-*** 51,56 ****
365
-  #include "server.h"
366
-  #include "tcpserver.h"
367
-  
368
-+ #ifndef	C_WINDOWS
369
-+ #define	closesocket(s)	close(s)
370
-+ #endif
371
-+ 
372
-  int tcpserver(const struct cfgstruct *copt)
373
-  {
374
-  	struct sockaddr_in server;
375
-***************
376
-*** 87,93 ****
377
-      if(bind(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) == -1) {
378
-  	estr = strerror(errno);
379
-  	logg("!TCP: bind() error: %s\n", estr);
380
-! 	close(sockfd);
381
-  	return -1;
382
-      } else {
383
-  	if(taddr->enabled)
384
-      if(bind(sockfd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) == -1) {
385
-  	estr = strerror(errno);
386
-  	logg("!TCP: bind() error: %s\n", estr);
387
-! 	closesocket(sockfd);
388
-  	return -1;
389
-      } else {
390
-  	if(taddr->enabled)
391
-***************
392
-*** 102,108 ****
393
-      if(listen(sockfd, backlog) == -1) {
394
-  	estr = strerror(errno);
395
-  	logg("!TCP: listen() error: %s\n", estr);
396
-! 	close(sockfd);
397
-  	return -1;
398
-      }
399
-  
400
-      if(listen(sockfd, backlog) == -1) {
401
-  	estr = strerror(errno);
402
-  	logg("!TCP: listen() error: %s\n", estr);
403
-! 	closesocket(sockfd);
404
-  	return -1;
405
-      }
406
-  
407 1
 *** /home/njh/src/clamav-devel/trunk/./clamdscan/client.c	2008-01-23 16:19:16.000000000 +0000
408 2
 --- ./clamdscan/client.c	2008-02-25 15:57:20.000000000 +0000
409 3
 ***************
... ...
@@ -1006,31 +567,3 @@
1006 1006
       exit(ret);
1007 1007
   }
1008 1008
   
1009
-*** /home/njh/src/clamav-devel/trunk/./libclamunrar_iface/unrar_iface.c	2007-12-26 13:58:50.000000000 +0000
1010
-***************
1011
-*** 542,544 ****
1012
-      free(state->unpack_data);
1013
-      free(state->comment_dir);
1014
-  }
1015
-+ 
1016
-+ #ifdef	C_WINDOWS
1017
-+ /*
1018
-+  * A copy is needed here to avoid a cyclic dependancy libclamunrar_iface<->libclamav
1019
-+  * e.g. see the comment in bug 775 about dropping the old internal snprintf
1020
-+  * which didn't have this problem and bug 785
1021
-+  */
1022
-+ #include <stdarg.h>
1023
-+ static int
1024
-+ snprintf(char *str, size_t size, const char *format, ...)
1025
-+ {
1026
-+ 	int ret;
1027
-+ 
1028
-+ 	va_list args;
1029
-+ 	va_start(args, format);
1030
-+ 	ret = _vsnprintf_s(str, size, _TRUNCATE, format, args);
1031
-+ 	va_end(args);
1032
-+ 	return ret;
1033
-+ }
1034
-+ #endif
... ...
@@ -32,24 +32,26 @@
32 32
 
33 33
 #include <stdio.h>
34 34
 #include <stdlib.h>
35
-#ifdef	HAVE_UNISTD_H
35
+#ifdef HAVE_UNISTD_H
36 36
 #include <unistd.h>
37 37
 #endif
38 38
 #include <string.h>
39 39
 #include <ctype.h>
40
-#ifndef	C_WINDOWS
40
+#ifndef C_WINDOWS
41 41
 #include <netinet/in.h>
42 42
 #include <netdb.h>
43 43
 #endif
44 44
 #include <sys/types.h>
45
-#ifndef	C_WINDOWS
45
+#ifndef C_WINDOWS
46 46
 #include <sys/socket.h>
47 47
 #include <sys/time.h>
48 48
 #endif
49 49
 #include <time.h>
50 50
 #include <fcntl.h>
51 51
 #include <sys/stat.h>
52
+#ifndef C_WINDOWS
52 53
 #include <dirent.h>
54
+#endif
53 55
 #include <errno.h>
54 56
 #include <zlib.h>
55 57
 
... ...
@@ -76,7 +78,7 @@
76 76
 #define	O_BINARY	0
77 77
 #endif
78 78
 
79
-#ifndef	C_WINDOWS
79
+#ifndef C_WINDOWS
80 80
 #define	closesocket(s)	close(s)
81 81
 #endif
82 82
 
... ...
@@ -212,7 +214,7 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip
212 212
 		break;
213 213
 	}
214 214
         logg("%cCan't get information about %s: %s\n", logerr ? '!' : '^', hostpt, herr);
215
-	close(socketfd);
215
+	closesocket(socketfd);
216 216
 	return -1;
217 217
     }
218 218
 
... ...
@@ -244,7 +246,7 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip
244 244
 	if(connect(socketfd, (struct sockaddr *) &name, sizeof(struct sockaddr_in)) == -1) {
245 245
 #endif
246 246
 	    logg("Can't connect to port %d of host %s (IP: %s)\n", port, hostpt, ipaddr);
247
-	    close(socketfd);
247
+	    closesocket(socketfd);
248 248
 	    if((socketfd = getclientsock(localip)) == -1)
249 249
 		return -1;
250 250
 
... ...
@@ -255,7 +257,7 @@ static int wwwconnect(const char *server, const char *proxy, int pport, char *ip
255 255
 	}
256 256
     }
257 257
 
258
-    close(socketfd);
258
+    closesocket(socketfd);
259 259
     return -2;
260 260
 }
261 261
 
... ...
@@ -918,7 +920,7 @@ static int buildcld(const char *tmpdir, const char *dbname, const char *newfile,
918 918
     }
919 919
 
920 920
     while((dent = readdir(dir))) {
921
-#ifndef C_INTERIX
921
+#if !defined(C_INTERIX) && !defined(C_WINDOWS)
922 922
 	if(dent->d_ino)
923 923
 #endif
924 924
 	{
... ...
@@ -542,3 +542,23 @@ void unrar_close(unrar_state_t *state)
542 542
     free(state->unpack_data);
543 543
     free(state->comment_dir);
544 544
 }
545
+
546
+#ifdef	C_WINDOWS
547
+/*
548
+ * A copy is needed here to avoid a cyclic dependancy libclamunrar_iface<->libclamav
549
+ * e.g. see the comment in bug 775 about dropping the old internal snprintf
550
+ * which didn't have this problem and bug 785
551
+ */
552
+#include <stdarg.h>
553
+static int
554
+snprintf(char *str, size_t size, const char *format, ...)
555
+{
556
+	int ret;
557
+
558
+	va_list args;
559
+	va_start(args, format);
560
+	ret = _vsnprintf_s(str, size, _TRUNCATE, format, args);
561
+	va_end(args);
562
+	return ret;
563
+}
564
+#endif