diff --git a/src/cjit.c b/src/cjit.c index 35ad1cc..d782abf 100644 --- a/src/cjit.c +++ b/src/cjit.c @@ -1233,7 +1233,11 @@ int main(int argc, char **argv) { free(code); tcc_delete(TCC); if(tmpdir) { +#ifndef LIBC_MINGW32 rm_recursive(tmpdir); +#else + win32_rmdtemp(tmpdir); +#endif } _err("---\nExecution completed"); exit(res); diff --git a/src/file.c b/src/file.c index 902c5c0..b86b831 100644 --- a/src/file.c +++ b/src/file.c @@ -247,4 +247,32 @@ char *win32_mkdtemp() { } return(tempDir); } +void win32_rmdtemp(const char *path) { + static char sysTempDir[MAX_PATH]; + static char secTempDir[MAX_PATH]; + static char winTempDir[MAX_PATH]; + PathCombine(sysTempDir, tempDir, "sys"); + rm_recursive(sysTempDir); + if (RemoveDirectory(sysTempDir) == 0) { + _err("Failed to remove sys dir in temporary dir: %s",path); + return; + } + PathCombine(secTempDir, tempDir, "sec_api"); + rm_recursive(secTempDir); + if (RemoveDirectory(secTempDir) == 0) { + _err("Failed to remove sec_api dir in temporary dir: %s",path); + return; + } + PathCombine(winTempDir, tempDir, "winapi"); + rm_recursive(winTempDir); + if (RemoveDirectory(winTempDir) == 0) { + _err("Failed to remove winapi dir in temporary dir: %s",path); + return; + } + rm_recursive(path); + if (RemoveDirectory(path) == 0) { + _err("Failed to remove temporary dir: %s",path); + return; + } +} #endif