Report more accurately the cause of the write error on Windows.

This commit is contained in:
Moritz Bunkus 2004-01-03 16:51:00 +00:00
parent 905b53dc14
commit 08a3d63550

View File

@ -218,11 +218,27 @@ uint32 mm_io_c::read(void *buffer, size_t size) {
return bytes_read;
}
size_t mm_io_c::write(const void *buffer,size_t size) {
size_t mm_io_c::write(const void *buffer, size_t size) {
DWORD bytes_written;
if (!WriteFile((HANDLE)file, buffer, size, &bytes_written, NULL))
return 0;
bytes_written = 0;
if (bytes_written != size) {
DWORD error;
char *error_msg;
error = GetLastError();
error_msg = NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&error_msg, 0, NULL);
mxerror("Cound not write to the output file: %d (%s)\n", error,
error_msg != NULL ? error_msg : "unknown");
}
return bytes_written;
}