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:
Tyler Dauwalder
2003-09-27 05:14:22 +00:00
parent c9d511cb96
commit 1eebd1e00a
2 changed files with 44 additions and 9 deletions
+22 -5
View File
@@ -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)
{ {
+22 -4
View File
@@ -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;