Browse code

contrib/DJGPP: add DJGPP patch from Blair <Blairdude*gmail.com> (bb#1317)

git-svn: trunk@4972

Tomasz Kojm authored on 2009/03/23 01:31:18
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sun Mar 22 17:30:03 CET 2009 (tk)
2
+---------------------------------
3
+ * contrib/DJGPP: add DJGPP patch from Blair <Blairdude*gmail.com> (bb#1317)
4
+
1 5
 Sun Mar 22 17:19:10 CET 2009 (tk)
2 6
 ---------------------------------
3 7
  * libclamav/special.c: fix possible false positive MS04-028 for files with
4 8
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+See https://wwws.clamav.net/bugzilla/show_bug.cgi?id=1317 for more
1
+information
0 2
new file mode 100644
... ...
@@ -0,0 +1,827 @@
0
+diff -ur clamav-orig/clamdtop/clamdtop.c clamav-new/clamdtop/clamdtop.c
1
+--- clamav-orig/clamdtop/clamdtop.c	2009-03-16 11:37:28.000000000 +1100
2
+@@ -47,8 +47,10 @@
3
+ #include <arpa/inet.h>
4
+ #include <netinet/in.h>
5
+ #include <sys/socket.h>
6
++#ifndef __DJGPP__
7
+ #include <sys/un.h>
8
+ #endif
9
++#endif
10
+ #include <sys/time.h>
11
+ #include <assert.h>
12
+ #include <errno.h>
13
+@@ -503,7 +505,7 @@
14
+ 	int s;
15
+ 	struct timeval tv;
16
+ 	conn->tcp = 0;
17
+-#ifdef _WIN32
18
++#if defined(_WIN32) || defined(__DJGPP__)
19
+     {
20
+ #else
21
+ 	if(soname[0] == '/' || (access(soname, F_OK) == 0)) {
22
+diff -ur clamav-orig/clamscan/clamscan.c clamav-new/clamscan/clamscan.c
23
+--- clamav-orig/clamscan/clamscan.c	2009-03-16 11:37:26.000000000 +1100
24
+@@ -80,7 +80,7 @@
25
+     }
26
+ #endif
27
+ 
28
+-#if !defined(C_WINDOWS) && !defined(C_BEOS)
29
++#if !defined(C_WINDOWS) && !defined(C_BEOS) && !defined(__DJGPP__)
30
+     sigemptyset(&sigset);
31
+     sigaddset(&sigset, SIGXFSZ);
32
+     sigprocmask(SIG_SETMASK, &sigset, NULL);
33
+diff -ur clamav-orig/clamscan/manager.c clamav-new/clamscan/manager.c
34
+--- clamav-orig/clamscan/manager.c	2009-03-16 11:37:26.000000000 +1100
35
+@@ -73,6 +73,11 @@
36
+ #define P_tmpdir    "C:\\WINDOWS\\TEMP"
37
+ #endif
38
+ 
39
++#ifdef __DJGPP__
40
++#undef P_tmpdir
41
++#define P_tmpdir    "/dev/env/TEMP"
42
++#endif
43
++
44
+ #ifndef	O_BINARY
45
+ #define	O_BINARY    0
46
+ #endif
47
+@@ -129,7 +134,7 @@
48
+ 	return 0;
49
+     }
50
+     info.rblocks += fsize / CL_COUNT_PRECISION;
51
+-#ifndef C_WINDOWS
52
++#if !defined(C_WINDOWS) && !defined(__DJGPP__)
53
+     if(geteuid())
54
+ 	if(checkaccess(filename, NULL, R_OK) != 1) {
55
+ 	    if(!printinfected)
56
+@@ -214,7 +219,7 @@
57
+ 
58
+     if((dd = opendir(dirname)) != NULL) {
59
+ 	while((dent = readdir(dd))) {
60
+-#if !defined(C_INTERIX) && !defined(C_WINDOWS)
61
++#if !defined(C_INTERIX) && !defined(C_WINDOWS) && !defined(__DJGPP__)
62
+ 	    if(dent->d_ino)
63
+ #endif
64
+ 	    {
65
+@@ -334,7 +339,7 @@
66
+ 	struct stat sb;
67
+ 	char *file, cwd[1024], *pua_cats = NULL;
68
+ 	const struct optstruct *opt;
69
+-#ifndef C_WINDOWS
70
++#if !defined(C_WINDOWS) && !defined(__DJGPP__)
71
+ 	struct rlimit rlim;
72
+ #endif
73
+ 
74
+@@ -468,7 +473,7 @@
75
+ 	}
76
+     }
77
+ 
78
+-#ifndef C_WINDOWS
79
++#if !defined(C_WINDOWS) && !defined(__DJGPP__)
80
+     if(getrlimit(RLIMIT_FSIZE, &rlim) == 0) {
81
+ 	if(rlim.rlim_max < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_FILESIZE, NULL))
82
+ 	    logg("^System limit for file size is lower than engine->maxfilesize\n");
83
+diff -ur clamav-orig/freshclam/freshclam.c clamav-new/freshclam/freshclam.c
84
+--- clamav-orig/freshclam/freshclam.c	2009-03-16 11:37:26.000000000 +1100
85
+@@ -438,7 +438,7 @@
86
+ 
87
+ 	logg("#freshclam daemon %s (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")\n", get_version());
88
+ 
89
+-#ifdef	C_WINDOWS
90
++#if	defined(C_WINDOWS) || defined(__DJGPP__)
91
+ 	signal(SIGINT, daemon_sighandler);
92
+ 	terminate = 0;
93
+ #else
94
+diff -ur clamav-orig/freshclam/manager.c clamav-new/freshclam/manager.c
95
+--- clamav-orig/freshclam/manager.c	2009-03-16 11:37:26.000000000 +1100
96
+@@ -1412,7 +1412,7 @@
97
+     }
98
+ 
99
+     while((dent = readdir(dir))) {
100
+-#if !defined(C_INTERIX) && !defined(C_WINDOWS)
101
++#if !defined(C_INTERIX) && !defined(C_WINDOWS) && !defined(__DJGPP__)
102
+ 	if(dent->d_ino)
103
+ #endif
104
+ 	{
105
+diff -ur clamav-orig/libclamav/binhex.c clamav-new/libclamav/binhex.c
106
+--- clamav-orig/libclamav/binhex.c	2009-03-16 11:37:28.000000000 +1100
107
+@@ -119,10 +119,6 @@
108
+ int
109
+ cli_binhex(const char *dir, int desc)
110
+ {
111
+-#ifndef HAVE_MMAP
112
+-	cli_warnmsg("File not decoded - binhex decoding needs mmap() (for now)\n");
113
+-	return CL_CLEAN;
114
+-#else
115
+ 	struct stat statb;
116
+ 	char *buf, *start, *line;
117
+ 	size_t size;
118
+@@ -142,7 +138,11 @@
119
+ 	if(m == NULL)
120
+ 		return CL_EMEM;
121
+ 
122
++#ifndef HAVE_MMAP
123
++	start = buf = cli_copy_file_to_mem(desc, size, 0);
124
++#else
125
+ 	start = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, 0);
126
++#endif
127
+ 	if(buf == MAP_FAILED) {
128
+ 		messageDestroy(m);
129
+ 		return CL_EMAP;
130
+@@ -187,7 +187,11 @@
131
+ 		buf = ++ptr;
132
+ 		bytesleft--;
133
+ 	}
134
++#ifndef HAVE_MMAP
135
++	free(start);
136
++#else
137
+ 	munmap(start, size);
138
++#endif
139
+ 
140
+ 	if(line)
141
+ 		free(line);
142
+@@ -213,5 +217,4 @@
143
+ 		return CL_CLEAN;	/* a lie - but it gets things going */
144
+ 	/* return CL_EIO; */	/* probably CL_EMEM, but we can't tell at this layer */
145
+ 	return CL_EMEM;
146
+-#endif
147
+ }
148
+diff -ur clamav-orig/libclamav/mbox.c clamav-new/libclamav/mbox.c
149
+--- clamav-orig/libclamav/mbox.c	2009-03-16 11:37:28.000000000 +1100
150
+@@ -3857,7 +3857,7 @@
151
+ 					int nblanks;
152
+ 					struct stat statb;
153
+ 					const char *dentry_idpart;
154
+-#ifndef C_WINDOWS
155
++#if (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
156
+ 					if(dent->d_ino == 0)
157
+ 						continue;
158
+ #endif
159
+diff -ur clamav-orig/libclamav/others.c clamav-new/libclamav/others.c
160
+--- clamav-orig/libclamav/others.c	2009-03-16 11:37:28.000000000 +1100
161
+@@ -81,6 +81,47 @@
162
+ #define       P_tmpdir        "C:\\WINDOWS\\TEMP"
163
+ #endif
164
+ 
165
++#ifdef 	      __DJGPP__
166
++#undef	      P_tmpdir
167
++#define       P_tmpdir	      "/dev/env/TEMP"
168
++
169
++/* DJGPP is missing pread/pwrite */
170
++ssize_t pread(int fd, void *data, size_t length, off_t offset )
171
++{
172
++        ssize_t result;
173
++        off_t save_offset;
174
++        int save_errno;
175
++
176
++        save_offset  = lseek(fd,offset,SEEK_SET);
177
++        if(save_offset==-1) return -1;
178
++
179
++        result = read(fd,data,length);
180
++
181
++        save_errno = errno;
182
++        lseek(fd, save_offset, SEEK_SET);
183
++        errno = save_errno;
184
++
185
++        return result;
186
++}
187
++
188
++#endif
189
++
190
++#ifndef HAVE_MMAP
191
++/* A partial mmap replacement for binhex and pdf scanning */
192
++void *cli_copy_file_to_mem( int fildes, size_t size, off_t offset )
193
++{
194
++	char *buf = malloc( size );
195
++
196
++	if( buf == NULL ) return( NULL );
197
++	if( pread( fildes, buf, size, offset ) == -1 ) {
198
++        	free( buf );
199
++        	return( NULL );
200
++	};
201
++
202
++	return( buf );
203
++}
204
++#endif
205
++
206
+ int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state);
207
+ int (*cli_unrar_extract_next_prepare)(unrar_state_t *state, const char *dirname);
208
+ int (*cli_unrar_extract_next)(unrar_state_t *state, const char *dirname);
209
+@@ -99,11 +140,19 @@
210
+     }
211
+     rhandle = lt_dlopenext("libclamunrar_iface");
212
+     if (!rhandle) {
213
++#ifdef __DJGPP__
214
++    cli_unrar_open = unrar_open;
215
++    cli_unrar_extract_next_prepare = unrar_extract_next_prepare;
216
++    cli_unrar_extract_next = unrar_extract_next;
217
++    cli_unrar_close = unrar_close;
218
++    have_rar = 1;
219
++#else
220
+ #ifdef WARN_DLOPEN_FAIL
221
+         cli_warnmsg("Cannot dlopen: %s - unrar support unavailable\n", lt_dlerror());
222
+ #else
223
+         cli_dbgmsg("Cannot dlopen: %s - unrar support unavailable\n", lt_dlerror());
224
+ #endif
225
++#endif
226
+         return;
227
+     }
228
+     if (!(cli_unrar_open = (int(*)(int, const char *, unrar_state_t *))lt_dlsym(rhandle, "unrar_open")) ||
229
+@@ -597,7 +646,7 @@
230
+ 	return 0;
231
+ }
232
+ 
233
+-#ifdef	C_WINDOWS
234
++#if defined(C_WINDOWS) || defined(__DJGPP__)
235
+ /*
236
+  * Windows doesn't allow you to delete a directory while it is still open
237
+  */
238
+@@ -702,7 +751,7 @@
239
+ #else
240
+ 	    while((dent = readdir(dd))) {
241
+ #endif
242
+-#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS))
243
++#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
244
+ 		if(dent->d_ino)
245
+ #endif
246
+ 		{
247
+diff -ur clamav-orig/libclamav/others.h clamav-new/libclamav/others.h
248
+--- clamav-orig/libclamav/others.h	2009-03-16 11:03:10.000000000 +1100
249
+@@ -358,6 +358,11 @@
250
+ void cli_dbgmsg_internal(const char *str, ...);
251
+ #endif
252
+ 
253
++#ifndef HAVE_MMAP
254
++void *cli_copy_file_to_mem(int fildes, size_t size, off_t offset);
255
++#define MAP_FAILED NULL
256
++#endif
257
++
258
+ void *cli_malloc(size_t nmemb);
259
+ void *cli_calloc(size_t nmemb, size_t size);
260
+ void *cli_realloc(void *ptr, size_t size);
261
+diff -ur clamav-orig/libclamav/others_common.c clamav-new/libclamav/others_common.c
262
+--- clamav-orig/libclamav/others_common.c	2009-03-16 11:37:28.000000000 +1100
263
+@@ -100,6 +100,221 @@
264
+     fputs(buff, stderr);				    \
265
+     va_end(args)
266
+ 
267
++#ifdef __DJGPP__
268
++/* 
269
++ * DJGPP is missing strptime (needed by freshclam)
270
++ * This is my own implementation
271
++ */
272
++
273
++
274
++static char *__day[] = {
275
++    "Sunday", "Monday", "Tuesday", "Wednesday",
276
++    "Thursday", "Friday", "Saturday"
277
++};
278
++
279
++static char *__month[] = {
280
++    "January", "February", "March", "April", "May", "June",
281
++    "July", "August", "September", "October", "November", "December"
282
++};
283
++
284
++static char *__ampm[] = {
285
++    "AM", "PM"
286
++};
287
++
288
++static int _strton( const char *nptr, const char * restrict *endptr, int max )
289
++{
290
++    int x = 0;
291
++
292
++    for( ;; ) {
293
++        if( !max ) break;
294
++        if( *nptr == '0' && !x ) {
295
++            nptr++;
296
++            continue;
297
++        }
298
++        if( isdigit( *nptr ) ) {
299
++            x = x * 10 + ( *nptr - '0' );
300
++            nptr++;
301
++            max--;
302
++        } else {
303
++            break;
304
++        }
305
++    }
306
++    *endptr = ( char * )nptr;
307
++
308
++    return( x );
309
++}
310
++
311
++char *strptime( const char * restrict buf, const char * restrict format,
312
++                struct tm * restrict tm )
313
++{
314
++    int w;
315
++    char *p;
316
++    int stri, len;
317
++
318
++    while( *format ) {
319
++        if( *format == '%' ) {
320
++            format++;
321
++            if( *format == 'E' || *format == 'O' ) format++;
322
++            switch( *format ) {
323
++                case '%':
324
++                    buf++;
325
++                    break;
326
++                case 'a':
327
++                case 'A':   /* Day of week full or abbreviated */
328
++                    for( w = 0; w < 7; w++ ) {
329
++                        p = __day[ w ];
330
++                        stri = 0;
331
++                        len = strlen( p );
332
++                        if( strnicmp( buf, p, len ) == 0 ) stri = len;
333
++                        else if( strnicmp( buf, p, 3 ) == 0 ) stri = 3;
334
++                        if( stri != 0 ) {
335
++                            tm->tm_wday = w;
336
++                            buf += stri;
337
++                            break;
338
++                        }
339
++                    }
340
++                    if( w == 7 ) return( NULL );
341
++                    break;
342
++                case 'b':
343
++                case 'B':
344
++                case 'h':
345
++                    for( w = 0; w < 12; w++ ) {
346
++                        p = __month[ w ];
347
++                        stri = 0;
348
++                        len = strlen( p );
349
++                        if( strnicmp( buf, p, len ) == 0 ) stri = len;
350
++                        else if( strnicmp( buf, p, 3 ) == 0 ) stri = 3;
351
++                        if( stri != 0 ) {
352
++                            tm->tm_mon = w;
353
++                            buf += stri;
354
++                            break;
355
++                        }
356
++                    }
357
++                    if( w == 12 ) return( NULL );
358
++                    break;
359
++                case 'c':
360
++                    buf = strptime( buf, "%a %b %d %R:%S %Y", tm );
361
++                    if( buf == NULL ) return( NULL );
362
++                    break;
363
++                case 'd':
364
++                case 'e':
365
++                    stri = _strton( buf, &buf, 2 );
366
++                    if( stri == 0 || stri > 31 ) return( NULL );
367
++                    tm->tm_mday = stri;
368
++                    break;
369
++                case 'D':
370
++                    if( ( buf = strptime( buf, "%m/%d/%y", tm ) ) == NULL )
371
++                        return( NULL );
372
++                    break;
373
++                case 'H':
374
++                    if( !isdigit( *buf ) ||
375
++                        ( stri = _strton( buf, &buf, 2 ) ) > 23 )
376
++                        return( NULL );
377
++                    tm->tm_hour = stri;
378
++                    break;
379
++                case 'I':
380
++                    stri = _strton( buf, &buf, 2 );
381
++                    if( stri < 1 || stri > 12 ) return( NULL );
382
++                    tm->tm_hour = stri - 1;
383
++                    break;
384
++                case 'j':
385
++                    stri = _strton( buf, &buf, 3 );
386
++                    if( stri < 1 || stri > 366 ) return( NULL );
387
++                    tm->tm_yday = stri;
388
++                    break;
389
++                case 'm':
390
++                    stri = _strton( buf, &buf, 2 );
391
++                    if( stri < 1 || stri > 12 ) return( NULL );
392
++                    tm->tm_mon = stri - 1;
393
++                    break;
394
++                case 'M':
395
++                    if( !isdigit( *buf ) ||
396
++                        ( stri = _strton( buf, &buf, 2 ) ) > 59 ) {
397
++                        return( NULL );
398
++                    }
399
++                    tm->tm_min = stri;
400
++                    break;
401
++                case 'n':
402
++                case 't':
403
++                    if( !isspace( *buf ) ) return( NULL );
404
++                    buf++;
405
++                    break;
406
++                case 'p':
407
++                    for( w = 0; w < 2; w++ ) {
408
++                        if( strnicmp( buf, __ampm[ w ], 2 ) == 0 ) break;
409
++                    }
410
++                    if( w == 2 ) return( NULL );
411
++                    if( w == 0 && tm->tm_hour > 11 ) tm->tm_hour -= 12;
412
++                    if( w == 1 && tm->tm_hour < 12 ) tm->tm_hour += 12;
413
++                    buf += 2;
414
++                    break;
415
++                case 'r':
416
++                    if( ( buf = strptime( buf, "%I:%M:%S%p", tm ) ) == NULL )
417
++                        return( NULL );
418
++                    break;
419
++                case 'R':
420
++                    if( ( buf = strptime( buf, "%H:%M", tm ) ) == NULL )
421
++                        return( NULL );
422
++                    break;
423
++                case 'S':
424
++                    if( !isdigit( *buf ) ||
425
++                        ( stri = _strton( buf, &buf, 2 ) ) > 60 )
426
++                        return( NULL );
427
++                    tm->tm_sec = stri;
428
++                    break;
429
++                case 'U':
430
++                    if( !isdigit( *buf ) ||
431
++                        ( stri = _strton( buf, &buf, 2 ) ) > 53 )
432
++                        return( NULL );
433
++                    w = stri * 7;
434
++                    if( stri % 7 > tm->tm_wday ) w++;
435
++                    tm->tm_yday = w;
436
++                    break;
437
++                case 'w':
438
++                    if( !isdigit( *buf ) ||
439
++                        ( stri = _strton( buf, &buf, 2 ) ) > 6 ) return( NULL );
440
++                    tm->tm_wday = stri;
441
++                    break;
442
++                case 'W':
443
++                    if( !isdigit( *buf ) ||
444
++                        ( stri = _strton( buf, &buf, 2 ) ) > 53 )
445
++                        return( NULL );
446
++                    w = stri * 7;
447
++                    if( stri % 7 > ( tm->tm_wday + 6 ) % 7 ) w++;
448
++                    tm->tm_yday = w;
449
++                    break;
450
++                case 'x':
451
++                    if( ( buf = strptime( buf, "%a %b %d %Y", tm ) ) == NULL )
452
++                        return( NULL );
453
++                    break;
454
++                case 'X':
455
++                    if( ( buf = strptime( buf, "%H:%M:%S", tm ) ) == NULL )
456
++                        return( NULL );
457
++                    break;
458
++                case 'y':
459
++                    stri = _strton( buf, &buf, 2 );
460
++                    if( stri > 99 ) return( NULL );
461
++                    tm->tm_year = ( stri < 69 ) ? 100 + stri : stri;
462
++                    break;
463
++                case 'Y':
464
++                    stri = _strton( buf, &buf, 4 );
465
++                    if( stri < 1969 || stri > 2068 ) return( NULL );
466
++                    tm->tm_year = stri - 1900;
467
++                    break;
468
++                default:
469
++                    buf++;
470
++            }
471
++        } else {
472
++            if( isspace( *format ) ) while( isspace( *buf ) ) buf++;
473
++            else if( *buf++ != *format ) return( NULL );
474
++        }
475
++        format++;
476
++    }
477
++    
478
++    return( ( char * )buf );
479
++}
480
++#endif
481
++
482
+ void cli_warnmsg(const char *str, ...)
483
+ {
484
+     MSGCODE("LibClamAV Warning: ");
485
+@@ -753,7 +968,12 @@
486
+ 	int i;
487
+ 
488
+     if(!dir) {
489
+-	if((mdir = getenv("TMPDIR")) == NULL)
490
++	mdir = getenv("TMPDIR");
491
++#ifdef __DJGPP__
492
++	if( mdir == NULL ) mdir = getenv("TEMP");
493
++	if( mdir == NULL ) mdir = getenv("TMP");
494
++#endif
495
++	if(mdir == NULL)
496
+ #ifdef P_tmpdir
497
+ 	    mdir = P_tmpdir;
498
+ #else
499
+@@ -789,12 +1009,17 @@
500
+ 	return NULL;
501
+     }
502
+ 
503
++#ifdef __DJGPP__ /* Support systems that don't have an lfn driver/interface */
504
++	sprintf(name, "%s/c", mdir);
505
++	strncat(name, tmp, 7);
506
++#else
507
+ #ifdef	C_WINDOWS
508
+ 	sprintf(name, "%s\\clamav-", mdir);
509
+ #else
510
+ 	sprintf(name, "%s/clamav-", mdir);
511
+ #endif
512
+     strncat(name, tmp, 32);
513
++#endif
514
+     free(tmp);
515
+ 
516
+     return(name);
517
+diff -ur clamav-orig/libclamav/pdf.c clamav-new/libclamav/pdf.c
518
+--- clamav-orig/libclamav/pdf.c	2009-03-16 11:37:28.000000000 +1100
519
+@@ -26,7 +26,6 @@
520
+ #include "clamav-config.h"
521
+ #endif
522
+ 
523
+-#ifdef	HAVE_MMAP
524
+ #include <stdio.h>
525
+ #include <sys/types.h>
526
+ #include <sys/stat.h>
527
+@@ -105,7 +104,11 @@
528
+ 	if(size <= 7)	/* doesn't even include the file header */
529
+ 		return CL_CLEAN;
530
+ 
531
++#ifndef HAVE_MMAP
532
++	p = buf = cli_copy_file_to_mem(desc, size, offset);
533
++#else
534
+ 	p = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, offset);
535
++#endif
536
+ 	if(buf == MAP_FAILED) {
537
+ 		cli_errmsg("cli_pdf: mmap() failed\n");
538
+ 		return CL_EMAP;
539
+@@ -126,7 +129,11 @@
540
+ 	}
541
+ 
542
+ 	if(!bytesleft) {
543
++#ifndef HAVE_MMAP
544
++	    free(buf);
545
++#else
546
+ 	    munmap(buf, size);
547
++#endif
548
+ 	    cli_dbgmsg("cli_pdf: file header not found\n");
549
+ 	    return CL_CLEAN;
550
+ 	}
551
+@@ -137,7 +144,11 @@
552
+ 			break;
553
+ 
554
+ 	if(q <= p) {
555
++#ifndef HAVE_MMAP
556
++		free(buf);
557
++#else
558
+ 		munmap(buf, size);
559
++#endif
560
+ 		cli_dbgmsg("cli_pdf: trailer not found\n");
561
+ 		return CL_CLEAN;
562
+ 	}
563
+@@ -156,7 +167,11 @@
564
+ 		 * http://www.cs.cmu.edu/~dst/Adobe/Gallery/anon21jul01-pdf-encryption.txt
565
+ 		 * http://www.adobe.com/devnet/pdf/
566
+ 		 */
567
++#ifndef HAVE_MMAP
568
++		free(buf);
569
++#else
570
+ 		munmap(buf, size);
571
++#endif
572
+ 		cli_dbgmsg("cli_pdf: Encrypted PDF files not yet supported\n");
573
+ 		return CL_CLEAN;
574
+ 	}
575
+@@ -179,7 +194,11 @@
576
+ 				break;
577
+ 
578
+ 	if(xrefstart == p) {
579
++#ifndef HAVE_MMAP
580
++		free(buf);
581
++#else
582
+ 		munmap(buf, size);
583
++#endif
584
+ 		cli_dbgmsg("cli_pdf: xref not found\n");
585
+ 		return CL_CLEAN;
586
+ 	}
587
+@@ -550,7 +569,11 @@
588
+ 		if(rc != CL_CLEAN) break;
589
+ 	}
590
+ 
591
++#ifndef HAVE_MMAP
592
++	free(buf);
593
++#else
594
+ 	munmap(buf, size);
595
++#endif
596
+ 
597
+ 	tableDestroy(md5table);
598
+ 
599
+@@ -886,16 +909,4 @@
600
+ 
601
+ 	return NULL;
602
+ }
603
+-#else	/*!HAVE_MMAP*/
604
+-
605
+-#include "clamav.h"
606
+-#include "others.h"
607
+-#include "pdf.h"
608
+ 
609
+-int
610
+-cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
611
+-{
612
+-	cli_dbgmsg("File not decoded - PDF decoding needs mmap() (for now)\n");
613
+-	return CL_CLEAN;
614
+-}
615
+-#endif
616
+diff -ur clamav-orig/libclamav/readdb.c clamav-new/libclamav/readdb.c
617
+--- clamav-orig/libclamav/readdb.c	2009-03-16 11:37:28.000000000 +1100
618
+@@ -1605,7 +1605,7 @@
619
+ #else
620
+     while((dent = readdir(dd))) {
621
+ #endif
622
+-#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS))
623
++#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
624
+ 	if(dent->d_ino)
625
+ #endif
626
+ 	{
627
+@@ -1719,7 +1719,7 @@
628
+ #else
629
+     while((dent = readdir(dd))) {
630
+ #endif
631
+-#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS))
632
++#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
633
+ 	if(dent->d_ino)
634
+ #endif
635
+ 	{
636
+@@ -1802,7 +1802,7 @@
637
+ #else
638
+     while((dent = readdir(dd))) {
639
+ #endif
640
+-#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS))
641
++#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
642
+ 	if(dent->d_ino)
643
+ #endif
644
+ 	{
645
+@@ -1909,6 +1909,16 @@
646
+ #ifdef CL_THREAD_SAFE
647
+     pthread_mutex_unlock(&cli_ref_mutex);
648
+ #endif
649
++/*
650
++ * I know that disabling this for DJGPP causes a GIANT memory leak if an app
651
++ * were to free the database and load it again, but if we let if free each
652
++ * tiny memory block, it literally takes at least 5-10min if not more to
653
++ * finish.  And in DOS all of the memory will automatically be freed when
654
++ * the app terminates, so the leak isn't permanent.  If mempool were to be
655
++ * available for systems without mmap, this would likely be a much better
656
++ * solution
657
++ */
658
++#ifndef __DJGPP__
659
+     if(engine->root) {
660
+ 	for(i = 0; i < CLI_MTARGETS; i++) {
661
+ 	    if((root = engine->root[i])) {
662
+@@ -1981,6 +1991,7 @@
663
+ 
664
+     cli_ftfree(engine);
665
+     cli_freeign(engine);
666
++#endif
667
+ #ifdef USE_MPOOL
668
+     if(engine->mempool) mpool_destroy(engine->mempool);
669
+ #endif
670
+diff -ur clamav-orig/libclamav/scanners.c clamav-new/libclamav/scanners.c
671
+--- clamav-orig/libclamav/scanners.c	2009-03-16 11:37:28.000000000 +1100
672
+@@ -128,7 +128,7 @@
673
+ #else
674
+ 	while((dent = readdir(dd))) {
675
+ #endif
676
+-#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS))
677
++#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
678
+ 	    if(dent->d_ino)
679
+ #endif
680
+ 	    {
681
+@@ -885,7 +885,7 @@
682
+ #else
683
+ 	while((dent = readdir(dd))) {
684
+ #endif
685
+-#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS))
686
++#if	(!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
687
+ 	    if(dent->d_ino)
688
+ #endif
689
+ 	    {
690
+diff -ur clamav-orig/shared/actions.c clamav-new/shared/actions.c
691
+--- clamav-orig/shared/actions.c	2009-03-16 11:37:26.000000000 +1100
692
+@@ -30,7 +30,9 @@
693
+ #include <fcntl.h>
694
+ #include <utime.h>
695
+ #include <errno.h>
696
++#ifndef __DJGPP__
697
+ #include <libgen.h>
698
++#endif
699
+ 
700
+ #include "shared/optparser.h"
701
+ #include "shared/output.h"
702
+diff -ur clamav-orig/shared/misc.h clamav-new/shared/misc.h
703
+--- clamav-orig/shared/misc.h	2009-03-16 11:37:26.000000000 +1100
704
+@@ -23,6 +23,7 @@
705
+ #include <netdb.h>
706
+ #include <netinet/in.h>
707
+ #include "optparser.h"
708
++
709
+ /* Maximum filenames under various systems - njh */
710
+ #ifndef	NAME_MAX	/* e.g. Linux */
711
+ # ifdef	MAXNAMELEN	/* e.g. Solaris */
712
+diff -ur clamav-orig/shared/optparser.c clamav-new/shared/optparser.c
713
+--- clamav-orig/shared/optparser.c	2009-03-16 11:48:00.000000000 +1100
714
+@@ -56,13 +56,19 @@
715
+ #define FLAG_REQUIRED	2 /* arg is required, even if there's a default value */
716
+ #define FLAG_HIDDEN	4 /* don't print in clamconf --generate-config */
717
+ 
718
++#ifdef __DJGPP__
719
++#define FRESHCLAM_CONF CONFDIR"/clamav.cnf"
720
++#else
721
++#define FRESHCLAM_CONF CONFDIR"/freshclam.conf"
722
++#endif
723
++
724
+ const struct clam_option clam_options[] = {
725
+     /* name,   longopt, sopt, argtype, regex, num, str, mul, owner, description, suggested */
726
+ 
727
+     /* cmdline only */
728
+     { NULL, "help", 'h', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP, "", "" },
729
+     { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR"/clamd.conf", FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDSCAN | OPT_CLAMDTOP, "", "" },
730
+-    { NULL, "config-file", 0, TYPE_STRING, NULL, 0, CONFDIR"/freshclam.conf", FLAG_REQUIRED, OPT_FRESHCLAM, "", "" },
731
++    { NULL, "config-file", 0, TYPE_STRING, NULL, 0, FRESHCLAM_CONF, FLAG_REQUIRED, OPT_FRESHCLAM, "", "" },
732
+     { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR"/clamav-milter.conf", FLAG_REQUIRED, OPT_MILTER, "", "" },
733
+     { NULL, "version", 'V', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP, "", "" },
734
+     { NULL, "debug", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_SIGTOOL, "", "" },
735
+diff -ur clamav-orig/sigtool/sigtool.c clamav-new/sigtool/sigtool.c
736
+--- clamav-orig/sigtool/sigtool.c	2009-03-16 11:37:26.000000000 +1100
737
+@@ -35,7 +35,9 @@
738
+ #include <sys/stat.h>
739
+ #include <fcntl.h>
740
+ #include <sys/socket.h>
741
++#ifndef __DJGPP__
742
+ #include <sys/un.h>
743
++#endif
744
+ #include <netinet/in.h>
745
+ #include <arpa/inet.h>
746
+ #include <sys/wait.h>
747
+@@ -987,7 +989,7 @@
748
+     }
749
+ 
750
+     while((dent = readdir(dd))) {
751
+-#ifndef C_INTERIX
752
++#if !defined(C_INTERIX) && !defined(__DJGPP__)
753
+ 	if(dent->d_ino)
754
+ #endif
755
+ 	{
756
+@@ -1469,7 +1471,7 @@
757
+     }
758
+ 
759
+     while((dent = readdir(dd))) {
760
+-#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
761
++#if (!defined(C_INTERIX)) && (!defined(C_WINDOWS)) && (!defined(__DJGPP__))
762
+ 	if(dent->d_ino)
763
+ #endif
764
+ 	{
765
+@@ -1617,7 +1619,7 @@
766
+     }
767
+ 
768
+     while((dent = readdir(dd))) {
769
+-#ifndef C_INTERIX
770
++#if !defined(C_INTERIX) && !defined(__DJGPP__)
771
+ 	if(dent->d_ino)
772
+ #endif
773
+ 	{
774
+@@ -1645,7 +1647,7 @@
775
+     }
776
+ 
777
+     while((dent = readdir(dd))) {
778
+-#ifndef C_INTERIX
779
++#if !defined(C_INTERIX) && !defined(__DJGPP__)
780
+ 	if(dent->d_ino)
781
+ #endif
782
+ 	{
783
+diff -ur clamav-orig/sigtool/vba.c clamav-new/sigtool/vba.c
784
+--- clamav-orig/sigtool/vba.c	2009-03-16 11:37:26.000000000 +1100
785
+@@ -970,7 +970,10 @@
786
+ 
787
+     if ((dd = opendir (dirname)) != NULL) {
788
+ 	while ((dent = readdir (dd))) {
789
+-	    if (dent->d_ino) {
790
++#ifndef __DJGPP__
791
++	    if (dent->d_ino)
792
++#endif
793
++        {
794
+ 		if (strcmp (dent->d_name, ".") && strcmp (dent->d_name, "..")) {
795
+ 		    /* build the full name */
796
+ 		    fname = (char *) cli_calloc (strlen (dirname) + strlen (dent->d_name) + 2, sizeof (char));
797
+@@ -1130,7 +1133,10 @@
798
+ 
799
+     if ((dd = opendir (dirname)) != NULL) {
800
+ 	while ((dent = readdir (dd))) {
801
+-	    if (dent->d_ino) {
802
++#ifndef __DJGPP__
803
++	    if (dent->d_ino)
804
++#endif
805
++        {
806
+ 		if (strcmp (dent->d_name, ".") && strcmp (dent->d_name, "..")) {
807
+ 		    /* build the full name */
808
+ 		    fullname = calloc (strlen (dirname) + strlen (dent->d_name) + 2, sizeof (char));