Browse code

c4w: mkdir *-p* ($tmpdir)

aCaB authored on 2010/12/30 00:20:21
Showing 1 changed files
... ...
@@ -28,6 +28,8 @@
28 28
 #include "clscanapi.h"
29 29
 #include "interface.h"
30 30
 
31
+int WINAPI SHCreateDirectoryExA(HWND, LPCTSTR, SECURITY_ATTRIBUTES *); /* cannot include Shlobj.h due to DATADIR collision */
32
+
31 33
 #define FMT(s) "!"__FUNCTION__": "s"\n"
32 34
 #define FAIL(errcode, fmt, ...) do { logg(FMT(fmt), __VA_ARGS__); return (errcode); } while(0)
33 35
 #define WIN() do { logg("*%s completed successfully\n", __FUNCTION__); return CLAMAPI_SUCCESS; } while(0)
... ...
@@ -373,12 +375,9 @@ int CLAMAPI Scan_Initialize(const wchar_t *pEnginesFolder, const wchar_t *pTempR
373 373
     }
374 374
     memcpy(&tmpdir[ret+1], "\\clamtmp", 9);
375 375
     cli_rmdirs(tmpdir);
376
-    if(!CreateDirectory(tmpdir, NULL)) {
377
-	ret = GetLastError();
378
-	if((DWORD)ret != ERROR_ALREADY_EXISTS) {
379
-	    free_engine_and_unlock();
380
-	    FAIL(CL_ETMPDIR, "Cannot create pTempRoot '%s': error %d", ret);
381
-	}
376
+    if((ret = SHCreateDirectoryExA(NULL, tmpdir, NULL) != ERROR_SUCCESS) && ret != ERROR_ALREADY_EXISTS) {
377
+	free_engine_and_unlock();
378
+	FAIL(CL_ETMPDIR, "Cannot create pTempRoot '%s': error %d", tmpdir, ret);
382 379
     }
383 380
     if((ret = cl_engine_set_str(engine, CL_ENGINE_TMPDIR, tmpdir))) {
384 381
 	free_engine_and_unlock();