Browse code

Handle more than 26 temporary files on Windows

git-svn: trunk@2197

Nigel Horne authored on 2006/08/16 00:07:58
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Tue Aug 15 16:07:11 BST 2006 (njh)
2
+----------------------------------
3
+  * libclamav/pdf.c:	Windows fix: handle more than 26 temporary files in
4
+				a temporary directory
5
+
1 6
 Sun Aug 13 22:13:45 CEST 2006 (tk)
2 7
 ----------------------------------
3 8
   * configure: add --enable-experimental switch
... ...
@@ -15,7 +15,7 @@
15 15
  *  along with this program; if not, write to the Free Software
16 16
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18
-static	char	const	rcsid[] = "$Id: pdf.c,v 1.53 2006/08/11 21:10:58 njh Exp $";
18
+static	char	const	rcsid[] = "$Id: pdf.c,v 1.54 2006/08/15 15:06:25 njh Exp $";
19 19
 
20 20
 #if HAVE_CONFIG_H
21 21
 #include "clamav-config.h"
... ...
@@ -43,6 +43,10 @@ static	char	const	rcsid[] = "$Id: pdf.c,v 1.53 2006/08/11 21:10:58 njh Exp $";
43 43
 #include <zlib.h>
44 44
 #endif
45 45
 
46
+#ifdef	C_WINDOWS
47
+#include <io.h>
48
+#endif
49
+
46 50
 #include "mbox.h"
47 51
 #include "pdf.h"
48 52
 
... ...
@@ -68,7 +72,7 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx)
68 68
 	int rc = CL_CLEAN;
69 69
 	struct table *md5table;
70 70
 
71
-	cli_dbgmsg("in cli_pdf()\n");
71
+	cli_dbgmsg("in cli_pdf(%s)\n", dir);
72 72
 
73 73
 	if(fstat(desc, &statb) < 0)
74 74
 		return CL_EOPEN;
... ...
@@ -181,11 +185,6 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx)
181 181
 			break;
182 182
 
183 183
 		/*object_number = atoi(q);*/
184
-
185
-		/*
186
-		 * FIXME: this assumes sizeof(int) == sizeof(char *), which
187
-		 *	isn't true on 64 bits machines
188
-		 */
189 184
 		bytesleft -= (q - p);
190 185
 		p = q;
191 186
 
... ...
@@ -284,8 +283,22 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx)
284 284
 		snprintf(fullname, sizeof(fullname), "%s/pdfXXXXXX", dir);
285 285
 #if	defined(C_LINUX) || defined(C_BSD) || defined(HAVE_MKSTEMP) || defined(C_SOLARIS) || defined(C_CYGWIN)
286 286
 		fout = mkstemp(fullname);
287
-#else
288
-		(void)mktemp(fullname);
287
+#elif	defined(C_WINDOWS)
288
+		if(_mktemp(fullname) == NULL) {
289
+			/* mktemp only allows 26 files */
290
+			char *name = cli_gentemp(dir);
291
+			if(name == NULL)
292
+				fout = -1;
293
+			else {
294
+				strcpy(fullname, name);
295
+				free(name);
296
+				fout = open(fullname,
297
+					O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0600);
298
+			}
299
+		} else
300
+			fout = open(fullname, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0600);
301
+#else	
302
+		mktemp(fullname);
289 303
 		fout = open(fullname, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0600);
290 304
 #endif
291 305