@@ -25,13 +25,14 @@ #ifdef HAVE_DLFCN_H # include #endif #import "OFException.h" -#import "OFString.h" #import "OFArray.h" #import "OFLocale.h" +#import "OFString.h" +#import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFUnlockFailedException.h" @@ -209,23 +210,43 @@ #ifdef OF_WINDOWS OFString * of_windows_status_to_string(LSTATUS status) { + OFString *string = nil; void *buffer; - OFString *string; - - if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, status, 0, (LPWSTR)&buffer, 0, - NULL) != 0) { - @try { - string = [OFString stringWithUTF16String: buffer]; - } @finally { - LocalFree(buffer); - } - } else + + if ([OFSystemInfo isWindowsNT]) { + if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, status, 0, + (LPWSTR)&buffer, 0, NULL) != 0) { + @try { + string = [OFString + stringWithUTF16String: buffer]; + } @finally { + LocalFree(buffer); + } + } + } else { + if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, status, 0, + (LPSTR)&buffer, 0, NULL) != 0) { + @try { + string = [OFString + stringWithCString: buffer + encoding: [OFLocale encoding]]; + } @finally { + LocalFree(buffer); + } + } + } + + if (string == nil) string = [OFString stringWithFormat: @"Status code %u", status]; return string; } #endif