Added the implementation of strnlen() and strlcat() as they are not part
of the R5 libroot.so. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3856 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
243a71e41e
commit
ee01d86fb8
@ -30,6 +30,54 @@ const char *kSettings[] = {
|
||||
};
|
||||
|
||||
|
||||
// needed by the driver_settings implementation, but not part of
|
||||
// the original R5 libroot.so
|
||||
|
||||
size_t
|
||||
strnlen(char const *string, size_t count)
|
||||
{
|
||||
const char *pos = string;
|
||||
|
||||
while (count-- && pos[0] != '\0')
|
||||
pos++;
|
||||
|
||||
return pos - string;
|
||||
}
|
||||
|
||||
|
||||
/** 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
|
||||
strlcat(char *dest, const char *source, size_t maxLength)
|
||||
{
|
||||
size_t destLength = strnlen(dest, maxLength);
|
||||
|
||||
// This returns the wrong size, but it's all we can do
|
||||
if (maxLength == destLength)
|
||||
return destLength + strlen(source);
|
||||
|
||||
dest += destLength;
|
||||
maxLength -= destLength;
|
||||
|
||||
size_t i = 0;
|
||||
for (; i < maxLength - 1 && source[i]; i++) {
|
||||
dest[i] = source[i];
|
||||
}
|
||||
|
||||
dest[i] = '\0';
|
||||
|
||||
return destLength + i + strlen(source + i);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
void
|
||||
put_level_space(int32 level)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user