Index: src/OFWin32ConsoleStdIOStream.m ================================================================== --- src/OFWin32ConsoleStdIOStream.m +++ src/OFWin32ConsoleStdIOStream.m @@ -49,10 +49,11 @@ #import "OFWin32ConsoleStdIOStream.h" #import "OFData.h" #import "OFStdIOStream+Private.h" #import "OFString.h" +#import "OFSystemInfo.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" @@ -136,21 +137,21 @@ @try { DWORD UTF16Len; OFMutableData *rest = nil; size_t i = 0; - if (!ReadConsoleW(_handle, UTF16, (DWORD)length, &UTF16Len, - NULL)) { - of_string_encoding_t encoding; - OFString *string; - size_t stringLen; - - if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) + if ([OFSystemInfo isWindowsNT]) { + if (!ReadConsoleW(_handle, UTF16, (DWORD)length, + &UTF16Len, NULL)) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length * 2 errNo: EIO]; + } else { + of_string_encoding_t encoding; + OFString *string; + size_t stringLen; if (!ReadConsoleA(_handle, (char *)UTF16, (DWORD)length, &UTF16Len, NULL)) @throw [OFReadFailedException exceptionWithObject: self @@ -313,29 +314,26 @@ UTF16[0] = c; UTF16Len = 1; } } - if (!WriteConsoleW(_handle, UTF16, UTF16Len, &bytesWritten, - NULL)) { - void *pool; - OFString *string; - of_string_encoding_t encoding; - size_t nativeLen; - - if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) + if ([OFSystemInfo isWindowsNT]) { + if (!WriteConsoleW(_handle, UTF16, UTF16Len, + &bytesWritten, NULL)) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: UTF16Len * 2 bytesWritten: bytesWritten * 2 errNo: EIO]; - - pool = objc_autoreleasePoolPush(); - string = [OFString stringWithUTF16String: UTF16 - length: UTF16Len]; - encoding = codepageToEncoding(GetConsoleOutputCP()); - nativeLen = [string + } else { + void *pool = objc_autoreleasePoolPush(); + OFString *string = [OFString + stringWithUTF16String: UTF16 + length: UTF16Len]; + of_string_encoding_t encoding = + codepageToEncoding(GetConsoleOutputCP()); + size_t nativeLen = [string cStringLengthWithEncoding: encoding]; if (nativeLen > UINT32_MAX) @throw [OFOutOfRangeException exception]; @@ -401,29 +399,25 @@ } if (j > UINT32_MAX) @throw [OFOutOfRangeException exception]; - if (!WriteConsoleW(_handle, tmp, (DWORD)j, &bytesWritten, - NULL)) { - void *pool; - OFString *string; - of_string_encoding_t encoding; - size_t nativeLen; - - if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) + if ([OFSystemInfo isWindowsNT]) { + if (!WriteConsoleW(_handle, tmp, (DWORD)j, + &bytesWritten, NULL)) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: EIO]; - - pool = objc_autoreleasePoolPush(); - string = [OFString stringWithUTF16String: tmp - length: j]; - encoding = codepageToEncoding(GetConsoleOutputCP()); - nativeLen = [string + } else { + void *pool = objc_autoreleasePoolPush(); + OFString *string = [OFString stringWithUTF16String: tmp + length: j]; + of_string_encoding_t encoding = + codepageToEncoding(GetConsoleOutputCP()); + size_t nativeLen = [string cStringLengthWithEncoding: encoding]; if (nativeLen > UINT32_MAX) @throw [OFOutOfRangeException exception];