Updated user_strlcpy() to return length of source string instead of 0.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4828 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -122,25 +122,42 @@ error:
|
|||||||
return B_BAD_ADDRESS;
|
return B_BAD_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \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
|
int
|
||||||
arch_cpu_user_strlcpy(char *to, const char *from, size_t size, addr *faultHandler)
|
arch_cpu_user_strlcpy(char *to, const char *from, size_t size, addr *faultHandler)
|
||||||
{
|
{
|
||||||
|
int from_length = 0;
|
||||||
|
|
||||||
*faultHandler = (addr)&&error;
|
*faultHandler = (addr)&&error;
|
||||||
|
|
||||||
to[--size] = '\0';
|
if (size > 0) {
|
||||||
while (size-- && (*to++ = *from++) != '\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++;
|
||||||
|
|
||||||
*faultHandler = 0;
|
*faultHandler = 0;
|
||||||
return 0;
|
return from_length;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
*faultHandler = 0;
|
*faultHandler = 0;
|
||||||
return B_BAD_ADDRESS;
|
return B_BAD_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
arch_cpu_user_memset(void *s, char c, size_t count, addr *faultHandler)
|
arch_cpu_user_memset(void *s, char c, size_t count, addr *faultHandler)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -195,18 +195,36 @@ error:
|
|||||||
return B_BAD_ADDRESS;
|
return B_BAD_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \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
|
int
|
||||||
arch_cpu_user_strlcpy(char *to, const char *from, size_t size, addr *faultHandler)
|
arch_cpu_user_strlcpy(char *to, const char *from, size_t size, addr *faultHandler)
|
||||||
{
|
{
|
||||||
|
int from_length = 0;
|
||||||
|
|
||||||
*faultHandler = (addr)&&error;
|
*faultHandler = (addr)&&error;
|
||||||
|
|
||||||
to[--size] = '\0';
|
if (size > 0) {
|
||||||
while (size-- && (*to++ = *from++) != '\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++;
|
||||||
|
|
||||||
*faultHandler = 0;
|
*faultHandler = 0;
|
||||||
return 0;
|
return from_length;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
*faultHandler = 0;
|
*faultHandler = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user