Differences From Artifact [2a51abc2a7]:
- File src/OFWin32ConsoleStdIOStream.m — part of check-in [bcf421d813] at 2020-05-17 00:58:16 on branch trunk — OFWin32ConsoleStdIOStream: Support for ANSI Win32 (user: js, size: 11474) [annotate] [blame] [check-ins using]
To Artifact [88e2ee5d8c]:
- File
src/OFWin32ConsoleStdIOStream.m
— part of check-in
[77bf56450b]
at
2020-05-17 10:42:49
on branch trunk
— OFWin32ConsoleStdIOStream: Use +[isWindowsNT]
This avoids the needless call to the W function first. This is safe to
do, as it's clear there won't ever be a non-NT Windows that supports
Unicode. (user: js, size: 11405) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <errno.h> #include <io.h> #import "OFWin32ConsoleStdIOStream.h" #import "OFData.h" #import "OFStdIOStream+Private.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" | > | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <errno.h> #include <io.h> #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" #import "OFWriteFailedException.h" |
︙ | ︙ | |||
134 135 136 137 138 139 140 | UTF16 = [self allocMemoryWithSize: sizeof(of_char16_t) count: length]; @try { DWORD UTF16Len; OFMutableData *rest = nil; size_t i = 0; | > | | < < < < < > > > > | 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | UTF16 = [self allocMemoryWithSize: sizeof(of_char16_t) count: length]; @try { DWORD UTF16Len; OFMutableData *rest = nil; size_t i = 0; 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 requestedLength: length errNo: EIO]; |
︙ | ︙ | |||
311 312 313 314 315 316 317 | UTF16Len = 2; } else { UTF16[0] = c; UTF16Len = 1; } } | > | | < < < < < < | | > | | > | | | 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | UTF16Len = 2; } else { UTF16[0] = c; UTF16Len = 1; } } if ([OFSystemInfo isWindowsNT]) { if (!WriteConsoleW(_handle, UTF16, UTF16Len, &bytesWritten, NULL)) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: UTF16Len * 2 bytesWritten: bytesWritten * 2 errNo: EIO]; } 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]; if (!WriteConsoleA(_handle, [string cStringWithEncoding: encoding], |
︙ | ︙ | |||
399 400 401 402 403 404 405 | i += UTF8Len; } if (j > UINT32_MAX) @throw [OFOutOfRangeException exception]; | > | | < < < < < < | | | | > | | | 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | i += UTF8Len; } if (j > UINT32_MAX) @throw [OFOutOfRangeException exception]; if ([OFSystemInfo isWindowsNT]) { if (!WriteConsoleW(_handle, tmp, (DWORD)j, &bytesWritten, NULL)) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: EIO]; } 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]; if (!WriteConsoleA(_handle, [string cStringWithEncoding: encoding], |
︙ | ︙ |