[kservice] implement rt_strcpy()

This commit is contained in:
Meco Man 2021-12-20 13:33:44 -05:00 committed by Bernard Xiong
parent acc62c1e3d
commit 457348e21a
2 changed files with 26 additions and 8 deletions

View File

@ -601,12 +601,13 @@ void *rt_memcpy(void *dest, const void *src, rt_ubase_t n);
char *rt_strdup(const char *s); char *rt_strdup(const char *s);
#ifndef RT_KSERVICE_USING_STDLIB #ifndef RT_KSERVICE_USING_STDLIB
void *rt_memmove(void *dest, const void *src, rt_ubase_t n); void *rt_memmove(void *dest, const void *src, rt_size_t n);
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);
char *rt_strstr(const char *str1, const char *str2); char *rt_strstr(const char *str1, const char *str2);
rt_int32_t rt_strcasecmp(const char *a, const char *b); rt_int32_t rt_strcasecmp(const char *a, const char *b);
char *rt_strncpy(char *dest, const char *src, rt_ubase_t n); char *rt_strcpy(char *dst, const char *src);
rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count); 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_int32_t rt_strcmp(const char *cs, const char *ct);
rt_size_t rt_strlen(const char *src); rt_size_t rt_strlen(const char *src);
#else #else
@ -615,6 +616,7 @@ rt_size_t rt_strlen(const char *src);
#define rt_memcmp(cs, ct, count) memcmp(cs, ct, count) #define rt_memcmp(cs, ct, count) memcmp(cs, ct, count)
#define rt_strstr(str1, str2) strstr(str1, str2) #define rt_strstr(str1, str2) strstr(str1, str2)
#define rt_strcasecmp(a, b) strcasecmp(a, b) #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_strncpy(dest, src, n) strncpy(dest, src, n)
#define rt_strncmp(cs, ct, count) strncmp(cs, ct, count) #define rt_strncmp(cs, ct, count) strncmp(cs, ct, count)
#define rt_strcmp(cs, ct) strcmp(cs, ct) #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. * 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. * 2015-07-06 Bernard Add rt_assert_handler routine.
* 2021-02-28 Meco Man add RT_KSERVICE_USING_STDLIB * 2021-02-28 Meco Man add RT_KSERVICE_USING_STDLIB
* 2021-12-20 Meco Man implement rt_strcpy()
*/ */
#include <rtthread.h> #include <rtthread.h>
@ -300,7 +301,7 @@ RTM_EXPORT(rt_memcpy);
* *
* @return The address of destination memory. * @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; char *tmp = (char *)dest, *s = (char *)src;
@ -336,7 +337,7 @@ RTM_EXPORT(rt_memmove);
* If the result > 0, cs is greater than ct. * If the result > 0, cs is greater than ct.
* If the result = 0, cs is equal to 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; const unsigned char *su1, *su2;
int res = 0; int res = 0;
@ -421,7 +422,7 @@ RTM_EXPORT(rt_strcasecmp);
* *
* @return The address where the copied content is stored. * @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) if (n != 0)
{ {
@ -444,6 +445,21 @@ char *rt_strncpy(char *dst, const char *src, rt_ubase_t n)
} }
RTM_EXPORT(rt_strncpy); 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. * This function will compare two strings with specified maximum length.
* *
@ -458,7 +474,7 @@ RTM_EXPORT(rt_strncpy);
* If the result > 0, cs is greater than ct. * If the result > 0, cs is greater than ct.
* If the result = 0, cs is equal to 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; register signed char __res = 0;