Fixed strlcat(); the old version assumed to have "maxLength" (3rd parameter)
bytes space *after* the dest string in the copy loop. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3857 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,21 +7,31 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
/** Concatenates the source string to the destination, writes
|
||||||
|
* as much as "maxLength" bytes to the dest string.
|
||||||
|
* Always null terminates the string as long as maxLength is
|
||||||
|
* larger than the dest string.
|
||||||
|
* Returns the length of the string that
|
||||||
|
*/
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
strlcat(char *dst, char const *src, size_t s)
|
strlcat(char *dest, const char *source, size_t maxLength)
|
||||||
{
|
{
|
||||||
size_t i, j = strnlen(dst, s);
|
size_t destLength = strnlen(dest, maxLength), i;
|
||||||
|
|
||||||
if (!s)
|
// This returns the wrong size, but it's all we can do
|
||||||
return j + strlen(src);
|
if (maxLength == destLength)
|
||||||
|
return destLength + strlen(source);
|
||||||
|
|
||||||
dst += j;
|
dest += destLength;
|
||||||
|
maxLength -= destLength;
|
||||||
|
|
||||||
for (i = 0; ((i < s-1) && src[i]); i++) {
|
for (i = 0; i < maxLength - 1 && source[i]; i++) {
|
||||||
dst[i] = src[i];
|
dest[i] = source[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
dst[i] = 0;
|
dest[i] = '\0';
|
||||||
|
|
||||||
return j + i + strlen(src + i);
|
return destLength + i + strlen(source + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user