ObjFW  Diff

Differences From Artifact [b94d48eb9c]:

To Artifact [e75a0d88c9]:


39
40
41
42
43
44
45

46
47
48
49
50
51
52
 */

#define OF_STDIO_STREAM_WIN32_CONSOLE_M

#include "config.h"

#include <assert.h>


#import "OFStdIOStream_Win32Console.h"
#import "OFStdIOStream+Private.h"
#import "OFString.h"
#import "OFDataArray.h"

#import "OFInvalidArgumentException.h"







>







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 */

#define OF_STDIO_STREAM_WIN32_CONSOLE_M

#include "config.h"

#include <assert.h>
#include <errno.h>

#import "OFStdIOStream_Win32Console.h"
#import "OFStdIOStream+Private.h"
#import "OFString.h"
#import "OFDataArray.h"

#import "OFInvalidArgumentException.h"
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
		OFDataArray *rest = nil;
		size_t i = 0;

		if (!ReadConsoleW(_handle, UTF16, (DWORD)length, &UTF16Len,
		    NULL))
			@throw [OFReadFailedException
			    exceptionWithObject: self
				requestedLength: length * 2];


		if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) {
			of_unichar_t c =
			    (((_incompleteUTF16Surrogate & 0x3FF) << 10) |
			    (UTF16[0] & 0x3FF)) + 0x10000;
			char UTF8[4];
			size_t UTF8Len;







|
>







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
		OFDataArray *rest = nil;
		size_t i = 0;

		if (!ReadConsoleW(_handle, UTF16, (DWORD)length, &UTF16Len,
		    NULL))
			@throw [OFReadFailedException
			    exceptionWithObject: self
				requestedLength: length * 2
					  errNo: EIO];

		if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) {
			of_unichar_t c =
			    (((_incompleteUTF16Surrogate & 0x3FF) << 10) |
			    (UTF16[0] & 0x3FF)) + 0x10000;
			char UTF8[4];
			size_t UTF8Len;
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
			}
		}

		if (!WriteConsoleW(_handle, UTF16, UTF16Len, &written, NULL) ||
		    written != UTF16Len)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: UTF16Len * 2];


		_incompleteUTF8SurrogateLen = 0;
		i += toCopy;
	}

	tmp = [self allocMemoryWithSize: sizeof(char16_t)
				  count: length * 2];







|
>







271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
			}
		}

		if (!WriteConsoleW(_handle, UTF16, UTF16Len, &written, NULL) ||
		    written != UTF16Len)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: UTF16Len * 2
					  errNo: EIO];

		_incompleteUTF8SurrogateLen = 0;
		i += toCopy;
	}

	tmp = [self allocMemoryWithSize: sizeof(char16_t)
				  count: length * 2];
320
321
322
323
324
325
326
327

328
329
330
331
332
		if (j > UINT32_MAX)
			@throw [OFOutOfRangeException exception];

		if (!WriteConsoleW(_handle, tmp, (DWORD)j, &written, NULL) ||
		    written != j)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: j * 2];

	} @finally {
		[self freeMemory: tmp];
	}
}
@end







|
>





323
324
325
326
327
328
329
330
331
332
333
334
335
336
		if (j > UINT32_MAX)
			@throw [OFOutOfRangeException exception];

		if (!WriteConsoleW(_handle, tmp, (DWORD)j, &written, NULL) ||
		    written != j)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: j * 2
					  errNo: EIO];
	} @finally {
		[self freeMemory: tmp];
	}
}
@end