ObjFW  Diff

Differences From Artifact [959c780c29]:

To Artifact [7dd85d6178]:


133
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
133
134
135
136
137
138
139

140

141
142
143
144
145
146
147







-
+
-







	char *buffer = buffer_;
	of_char16_t *UTF16;
	size_t j = 0;

	if (length > UINT32_MAX)
		@throw [OFOutOfRangeException exception];

	UTF16 = [self allocMemoryWithSize: sizeof(of_char16_t)
	UTF16 = of_malloc(length, 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,
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269







-
+







			}
		}

		if (rest != nil)
			[self unreadFromBuffer: rest.items
					length: rest.count];
	} @finally {
		[self freeMemory: UTF16];
		free(UTF16);
	}

	objc_autoreleasePoolPop(pool);

	return j;
}

361
362
363
364
365
366
367
368

369
370
371
372
373
374
375
376
360
361
362
363
364
365
366

367

368
369
370
371
372
373
374







-
+
-







				   bytesWritten: bytesWritten * 2
					  errNo: 0];

		_incompleteUTF8SurrogateLen = 0;
		i += toCopy;
	}

	tmp = [self allocMemoryWithSize: sizeof(of_char16_t)
	tmp = of_malloc(length * 2, sizeof(of_char16_t));
				  count: length * 2];
	@try {
		DWORD bytesWritten;

		while (i < length) {
			of_unichar_t c;
			ssize_t UTF8Len;

441
442
443
444
445
446
447
448

449
450
451
452
453
454
455
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453







-
+







		if (bytesWritten != j)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: j * 2
				   bytesWritten: bytesWritten * 2
					  errNo: 0];
	} @finally {
		[self freeMemory: tmp];
		free(tmp);
	}

	/*
	 * We do not count in bytes when writing to the Win32 console. But
	 * since any incomplete write is an exception here anyway, we can just
	 * return length.
	 */