Added user_strlcpy() and user_memcpy().
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4836 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
fcb83407a1
commit
5e47f0f341
@ -637,3 +637,49 @@ dprintf(const char *format,...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
extern "C" int user_memcpy(void *to, const void *from, size_t size);
|
||||
extern "C" int user_strlcpy(char *to, const char *from, size_t size);
|
||||
|
||||
// user_memcpy
|
||||
int
|
||||
user_memcpy(void *to, const void *from, size_t size)
|
||||
{
|
||||
char *tmp = (char *)to;
|
||||
char *s = (char *)from;
|
||||
|
||||
while (size--)
|
||||
*tmp++ = *s++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// user_strlcpy
|
||||
/*! \brief Copies at most (\a size - 1) characters from the string in \a from to
|
||||
the string in \a to, NULL-terminating the result.
|
||||
|
||||
\param to Pointer to the destination C-string.
|
||||
\param from Pointer to the source C-string.
|
||||
\param size Size in bytes of the string buffer pointed to by \a to.
|
||||
|
||||
\return strlen(\a from).
|
||||
*/
|
||||
int
|
||||
user_strlcpy(char *to, const char *from, size_t size)
|
||||
{
|
||||
int from_length = 0;
|
||||
|
||||
if (size > 0) {
|
||||
to[--size] = '\0';
|
||||
// copy
|
||||
for ( ; size; size--, from_length++, to++, from++) {
|
||||
if ((*to = *from) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
// count any leftover from chars
|
||||
while (*from++ != '\0')
|
||||
from_length++;
|
||||
|
||||
return from_length;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user