Overview
Comment: | OFWin32ConsoleStdIOStream: Use +[isWindowsNT]
This avoids the needless call to the W function first. This is safe to |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
77bf56450bff5c53c2f196c189fb26a0 |
User & Date: | js on 2020-05-17 10:42:49 |
Other Links: | manifest | tags |
Context
2020-05-17
| ||
11:04 | OFApplication: Support for non-Unicode Windows check-in: 5292d2fd54 user: js tags: trunk | |
10:42 | OFWin32ConsoleStdIOStream: Use +[isWindowsNT] check-in: 77bf56450b user: js tags: trunk | |
10:32 | Add +[OFSystemInfo isWindowsNT] check-in: 793fdb6630 user: js tags: trunk | |
Changes
Modified src/OFWin32ConsoleStdIOStream.m from [2a51abc2a7] to [88e2ee5d8c].
47 48 49 50 51 52 53 54 55 56 57 58 59 60 ... 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 ... 311 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 342 343 ... 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 426 427 428 429 430 431 |
#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" ................................................................................ UTF16 = [self allocMemoryWithSize: sizeof(of_char16_t) count: length]; @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) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length * 2 errNo: EIO]; if (!ReadConsoleA(_handle, (char *)UTF16, (DWORD)length, &UTF16Len, NULL)) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: EIO]; ................................................................................ UTF16Len = 2; } else { 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) @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 cStringLengthWithEncoding: encoding]; if (nativeLen > UINT32_MAX) @throw [OFOutOfRangeException exception]; if (!WriteConsoleA(_handle, [string cStringWithEncoding: encoding], ................................................................................ i += UTF8Len; } 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) @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 cStringLengthWithEncoding: encoding]; if (nativeLen > UINT32_MAX) @throw [OFOutOfRangeException exception]; if (!WriteConsoleA(_handle, [string cStringWithEncoding: encoding], |
> > | | < < < < < > > > > > | | < < < < < < < > | > | | > | | > | | < < < < < < < > | | | > | | |
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 ... 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 ... 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 ... 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 |
#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" ................................................................................ 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]; ................................................................................ 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], ................................................................................ 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], |