1/*
2** Copyright 2002, Manuel J. Petit.
3** Copyright 2011, Oliver Tappe <zooey@hirschkafer.de>.
4** All rights reserved. Distributed under the terms of the NewOS License.
5*/
6
7#include <wchar_private.h>
8
9
10/** Concatenates the source string to the destination, writes
11 *	as much as "maxLength" bytes to the dest string.
12 *	Always null terminates the string as long as maxLength is
13 *	larger than the dest string.
14 *	Returns the length of the string that it tried to create
15 *	to be able to easily detect string truncation.
16 */
17
18size_t
19__wcslcat(wchar_t* dest, const wchar_t* source, size_t maxLength)
20{
21	size_t destLength = __wcsnlen(dest, maxLength);
22	size_t i;
23
24	if (destLength == maxLength) {
25		// the destination is already full
26		return destLength + __wcslen(source);
27	}
28
29	dest += destLength;
30	maxLength -= destLength;
31
32	for (i = 0; i < maxLength - 1 && *source != L'\0'; ++i)
33		*dest++ = *source++;
34
35	*dest = '\0';
36
37	return destLength + i + __wcslen(source);
38}
39
40
41B_DEFINE_WEAK_ALIAS(__wcslcat, wcslcat);
42