2 ** Copyright 2002, Manuel J. Petit. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
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.
19 strlcat(char *dest
, const char *source
, size_t maxLength
)
21 size_t destLength
= strnlen(dest
, maxLength
), i
;
23 // This returns the wrong size, but it's all we can do
24 if (maxLength
== destLength
)
25 return destLength
+ strlen(source
);
28 maxLength
-= destLength
;
30 for (i
= 0; i
< maxLength
- 1 && source
[i
]; i
++) {
36 return destLength
+ i
+ strlen(source
+ i
);