[kservice] implement rt_strcpy()

This commit is contained in:
Meco Man 2021-12-20 13:33:44 -05:00 committed by chinky
parent 158bb5e9d5
commit 1218f9c02b
2 changed files with 26 additions and 8 deletions

View File

@ -567,12 +567,13 @@ void *rt_memcpy(void *dest, const void *src, rt_ubase_t n);
char *rt_strdup(const char *s);
#ifndef RT_KSERVICE_USING_STDLIB
void *rt_memmove(void *dest, const void *src, rt_ubase_t n);
rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count);
void *rt_memmove(void *dest, const void *src, rt_size_t n);
rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_size_t count);
char *rt_strstr(const char *str1, const char *str2);
rt_int32_t rt_strcasecmp(const char *a, const char *b);
char *rt_strncpy(char *dest, const char *src, rt_ubase_t n);
rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count);
char *rt_strcpy(char *dst, const char *src);
char *rt_strncpy(char *dest, const char *src, rt_size_t n);
rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_size_t count);
rt_int32_t rt_strcmp(const char *cs, const char *ct);
rt_size_t rt_strlen(const char *src);
#else
@ -581,6 +582,7 @@ rt_size_t rt_strlen(const char *src);
#define rt_memcmp(cs, ct, count) memcmp(cs, ct, count)
#define rt_strstr(str1, str2) strstr(str1, str2)
#define rt_strcasecmp(a, b) strcasecmp(a, b)
#define rt_strcpy(dest, src) strcpy(dest, src)
#define rt_strncpy(dest, src, n) strncpy(dest, src, n)
#define rt_strncmp(cs, ct, count) strncmp(cs, ct, count)
#define rt_strcmp(cs, ct) strcmp(cs, ct)

View File

@ -18,6 +18,7 @@
* 2013-09-24 aozima make sure the device is in STREAM mode when used by rt_kprintf.
* 2015-07-06 Bernard Add rt_assert_handler routine.
* 2021-02-28 Meco Man add RT_KSERVICE_USING_STDLIB
* 2021-12-20 Meco Man implement rt_strcpy()
*/
#include <rtthread.h>
@ -302,7 +303,7 @@ RTM_EXPORT(rt_memcpy);
*
* @return The address of destination memory.
*/
void *rt_memmove(void *dest, const void *src, rt_ubase_t n)
void *rt_memmove(void *dest, const void *src, rt_size_t n)
{
char *tmp = (char *)dest, *s = (char *)src;
@ -338,7 +339,7 @@ RTM_EXPORT(rt_memmove);
* If the result > 0, cs is greater than ct.
* If the result = 0, cs is equal to ct.
*/
rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count)
rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_size_t count)
{
const unsigned char *su1, *su2;
int res = 0;
@ -423,7 +424,7 @@ RTM_EXPORT(rt_strcasecmp);
*
* @return The address where the copied content is stored.
*/
char *rt_strncpy(char *dst, const char *src, rt_ubase_t n)
char *rt_strncpy(char *dst, const char *src, rt_size_t n)
{
if (n != 0)
{
@ -446,6 +447,21 @@ char *rt_strncpy(char *dst, const char *src, rt_ubase_t n)
}
RTM_EXPORT(rt_strncpy);
/**
* This function will copy string.
*
* @param dst points to the address used to store the copied content.
*
* @param src is the string to be copied.
*
* @return The address where the copied content is stored.
*/
char *rt_strcpy(char *dst, const char *src)
{
return rt_strncpy(dst, src, (rt_size_t)-1);
}
RTM_EXPORT(rt_strcpy);
/**
* This function will compare two strings with specified maximum length.
*
@ -460,7 +476,7 @@ RTM_EXPORT(rt_strncpy);
* If the result > 0, cs is greater than ct.
* If the result = 0, cs is equal to ct.
*/
rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count)
rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_size_t count)
{
register signed char __res = 0;