ObjFW  Diff

Differences From Artifact [2a51abc2a7]:

To Artifact [88e2ee5d8c]:


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

141
142
143
144
145
146
147
148
149
150
151




152
153
154
155
156
157
158
	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];







>
|
|
<
<
<
<
<




>
>
>
>







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

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
				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],







>
|
|
<
<
<
<
<
<





|
|
>
|
|
>
|
|







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

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

			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],







>
|
|
<
<
<
<
<
<





|
|
|
|
>
|
|







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],