diff --git a/src/plat.h b/src/plat.h index fd062f8..be41fc8 100644 --- a/src/plat.h +++ b/src/plat.h @@ -8,7 +8,7 @@ * * Define the various platform support functions. * - * Version: @(#)plat.h 1.0.16 2018/05/18 + * Version: @(#)plat.h 1.0.17 2018/08/31 * * Author: Fred N. van Kempen, * @@ -130,6 +130,7 @@ extern FILE *plat_fopen(const wchar_t *path, const wchar_t *mode); extern void plat_remove(const wchar_t *path); extern int plat_getcwd(wchar_t *bufp, int max); extern int plat_chdir(const wchar_t *path); +extern void plat_tempfile(wchar_t *bufp, const wchar_t *prefix, const wchar_t *suffix); extern void plat_get_exe_name(wchar_t *path, int size); extern wchar_t *plat_get_basename(const wchar_t *path); extern wchar_t *plat_get_filename(const wchar_t *path); diff --git a/src/win/win.c b/src/win/win.c index 95e5d83..3c90778 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -367,6 +367,26 @@ plat_get_exe_name(wchar_t *bufp, int size) } +void +plat_tempfile(wchar_t *bufp, const wchar_t *prefix, const wchar_t *suffix) +{ + SYSTEMTIME SystemTime; + char temp[1024]; + + if (prefix != NULL) + sprintf(temp, "%ls", prefix); + else + strcpy(temp, EMU_NAME); + + GetSystemTime(&SystemTime); + sprintf(&temp[strlen(temp)], "-%d%02d%02d-%02d-%02d-%02d-%03d%ls", + SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay, SystemTime.wHour, + SystemTime.wMinute, SystemTime.wSecond, SystemTime.wMilliseconds, + suffix); + mbstowcs(bufp, temp, strlen(temp)+1); +} + + int plat_getcwd(wchar_t *bufp, int max) { diff --git a/src/win/win_crashdump.c b/src/win/win_crashdump.c index cbe006a..25affbe 100644 --- a/src/win/win_crashdump.c +++ b/src/win/win_crashdump.c @@ -8,7 +8,7 @@ * * Handle generation of crash-dump reports. * - * Version: @(#)win_crashdump.c 1.0.6 2018/03/20 + * Version: @(#)win_crashdump.c 1.0.7 2018/08/31 * * Authors: Fred N. van Kempen, * Riley (Rai-chan), @@ -53,6 +53,7 @@ static PVOID hExceptionHandler; static char *ExceptionHandlerBuffer, *CurrentBufferPointer; +static char ExceptionHandlerFileName[1024]; static LONG CALLBACK @@ -63,6 +64,9 @@ MakeCrashDump(PEXCEPTION_POINTERS ExceptionInfo) char *BufPtr; DWORD i; + /* Get current system date and time. */ + GetSystemTime(&SystemTime); + /* * Win32-specific functions will be used wherever possible, * just in case the C stdlib-equivalents try to allocate @@ -113,20 +117,14 @@ MakeCrashDump(PEXCEPTION_POINTERS ExceptionInfo) * It should contain the current date and time so as * to be (hopefully!) unique. */ - GetSystemTime(&SystemTime); - sprintf(CurrentBufferPointer, - "%s-%d%02d%02d-%02d-%02d-%02d-%03d.dmp", EMU_NAME, - SystemTime.wYear, - SystemTime.wMonth, - SystemTime.wDay, - SystemTime.wHour, - SystemTime.wMinute, - SystemTime.wSecond, - SystemTime.wMilliseconds); + plat_tempfile((wchar_t *)ExceptionHandlerBuffer, NULL, DUMP_FILE_EXT); + wcstombs(ExceptionHandlerFileName, (wchar_t *)ExceptionHandlerBuffer, + sizeof(ExceptionHandlerFileName)); + /* Now the filename is in the buffer, the file can be created. */ hDumpFile = CreateFile( - ExceptionHandlerBuffer, // The filename of the file to open. + ExceptionHandlerFileName, // The filename of the file to open. GENERIC_WRITE, // The permissions to request. 0, // Make sure other processes can't // touch the crash dump at all