Skip to content

Commit 867551f

Browse files
CopilotBernardXiong
andcommitted
Update klibc function signatures to match standard libc
Co-authored-by: BernardXiong <[email protected]>
1 parent dcb3f88 commit 867551f

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

include/klibc/kstring.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717
extern "C" {
1818
#endif
1919

20-
void *rt_memset(void *src, int c, rt_ubase_t n);
21-
void *rt_memcpy(void *dest, const void *src, rt_ubase_t n);
22-
void *rt_memmove(void *dest, const void *src, rt_size_t n);
23-
rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_size_t count);
20+
void *rt_memset(void *s, int c, size_t n);
21+
void *rt_memcpy(void *dest, const void *src, size_t n);
22+
void *rt_memmove(void *dest, const void *src, size_t n);
23+
int rt_memcmp(const void *cs, const void *ct, size_t count);
2424

2525
char *rt_strdup(const char *s);
26-
rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen);
26+
size_t rt_strnlen(const char *s, size_t maxlen);
2727
char *rt_strstr(const char *str1, const char *str2);
28-
rt_int32_t rt_strcasecmp(const char *a, const char *b);
28+
int rt_strcasecmp(const char *a, const char *b);
2929
char *rt_strcpy(char *dst, const char *src);
30-
char *rt_strncpy(char *dest, const char *src, rt_size_t n);
31-
rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_size_t count);
32-
rt_int32_t rt_strcmp(const char *cs, const char *ct);
33-
rt_size_t rt_strlen(const char *src);
30+
char *rt_strncpy(char *dest, const char *src, size_t n);
31+
int rt_strncmp(const char *cs, const char *ct, size_t count);
32+
int rt_strcmp(const char *cs, const char *ct);
33+
size_t rt_strlen(const char *src);
3434

3535
#ifdef __cplusplus
3636
}

src/klibc/kstring.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @return The address of source memory.
3737
*/
3838
#ifndef RT_KLIBC_USING_USER_MEMSET
39-
void *rt_memset(void *s, int c, rt_ubase_t count)
39+
void *rt_memset(void *s, int c, size_t count)
4040
{
4141
#if defined(RT_KLIBC_USING_LIBC_MEMSET)
4242
return memset(s, c, count);
@@ -121,13 +121,13 @@ RTM_EXPORT(rt_memset);
121121
* @return The address of destination memory
122122
*/
123123
#ifndef RT_KLIBC_USING_USER_MEMCPY
124-
void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
124+
void *rt_memcpy(void *dst, const void *src, size_t count)
125125
{
126126
#if defined(RT_KLIBC_USING_LIBC_MEMCPY)
127127
return memcpy(dst, src, count);
128128
#elif defined(RT_KLIBC_USING_TINY_MEMCPY)
129129
char *tmp = (char *)dst, *s = (char *)src;
130-
rt_ubase_t len = 0;
130+
size_t len = 0;
131131

132132
if (tmp <= s || tmp > (s + count))
133133
{
@@ -153,7 +153,7 @@ void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
153153
char *src_ptr = (char *)src;
154154
long *aligned_dst = RT_NULL;
155155
long *aligned_src = RT_NULL;
156-
rt_ubase_t len = count;
156+
size_t len = count;
157157

158158
/* If the size is small, or either SRC or DST is unaligned,
159159
then punt into the byte copy loop. This should be rare. */
@@ -211,7 +211,7 @@ RTM_EXPORT(rt_memcpy);
211211
* @return The address of destination memory.
212212
*/
213213
#ifndef RT_KLIBC_USING_USER_MEMMOVE
214-
void *rt_memmove(void *dest, const void *src, rt_size_t n)
214+
void *rt_memmove(void *dest, const void *src, size_t n)
215215
{
216216
#ifdef RT_KLIBC_USING_LIBC_MEMMOVE
217217
return memmove(dest, src, n);
@@ -253,7 +253,7 @@ RTM_EXPORT(rt_memmove);
253253
* If the result = 0, cs is equal to ct.
254254
*/
255255
#ifndef RT_KLIBC_USING_USER_MEMCMP
256-
rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_size_t count)
256+
int rt_memcmp(const void *cs, const void *ct, size_t count)
257257
{
258258
#ifdef RT_KLIBC_USING_LIBC_MEMCMP
259259
return memcmp(cs, ct, count);
@@ -326,7 +326,7 @@ RTM_EXPORT(rt_strstr);
326326
* If the result = 0, a is equal to a.
327327
*/
328328
#ifndef RT_KLIBC_USING_USER_STRCASECMP
329-
rt_int32_t rt_strcasecmp(const char *a, const char *b)
329+
int rt_strcasecmp(const char *a, const char *b)
330330
{
331331
int ca = 0, cb = 0;
332332

@@ -358,7 +358,7 @@ RTM_EXPORT(rt_strcasecmp);
358358
* @return The address where the copied content is stored.
359359
*/
360360
#ifndef RT_KLIBC_USING_USER_STRNCPY
361-
char *rt_strncpy(char *dst, const char *src, rt_size_t n)
361+
char *rt_strncpy(char *dst, const char *src, size_t n)
362362
{
363363
#ifdef RT_KLIBC_USING_LIBC_STRNCPY
364364
return strncpy(dst, src, n);
@@ -435,7 +435,7 @@ RTM_EXPORT(rt_strcpy);
435435
* If the result = 0, cs is equal to ct.
436436
*/
437437
#ifndef RT_KLIBC_USING_USER_STRNCMP
438-
rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_size_t count)
438+
int rt_strncmp(const char *cs, const char *ct, size_t count)
439439
{
440440
#ifdef RT_KLIBC_USING_LIBC_STRNCMP
441441
return strncmp(cs, ct, count);
@@ -471,7 +471,7 @@ RTM_EXPORT(rt_strncmp);
471471
* If the result = 0, cs is equal to ct.
472472
*/
473473
#ifndef RT_KLIBC_USING_USER_STRCMP
474-
rt_int32_t rt_strcmp(const char *cs, const char *ct)
474+
int rt_strcmp(const char *cs, const char *ct)
475475
{
476476
#ifdef RT_KLIBC_USING_LIBC_STRCMP
477477
return strcmp(cs, ct);
@@ -497,7 +497,7 @@ RTM_EXPORT(rt_strcmp);
497497
* @return The length of string.
498498
*/
499499
#ifndef RT_KLIBC_USING_USER_STRLEN
500-
rt_size_t rt_strlen(const char *s)
500+
size_t rt_strlen(const char *s)
501501
{
502502
#ifdef RT_KLIBC_USING_LIBC_STRLEN
503503
return strlen(s);
@@ -524,10 +524,10 @@ RTM_EXPORT(rt_strlen);
524524
* @return The length of string.
525525
*/
526526
#ifndef RT_KLIBC_USING_USER_STRNLEN
527-
rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen)
527+
size_t rt_strnlen(const char *s, size_t maxlen)
528528
{
529529
const char *sc;
530-
for (sc = s; *sc != '\0' && (rt_ubase_t)(sc - s) < maxlen; ++sc);
530+
for (sc = s; *sc != '\0' && (size_t)(sc - s) < maxlen; ++sc);
531531
return sc - s;
532532
}
533533
#endif /* RT_KLIBC_USING_USER_STRNLEN */
@@ -543,7 +543,7 @@ RTM_EXPORT(rt_strnlen);
543543
*/
544544
char *rt_strdup(const char *s)
545545
{
546-
rt_size_t len = rt_strlen(s) + 1;
546+
size_t len = rt_strlen(s) + 1;
547547
char *tmp = (char *)rt_malloc(len);
548548

549549
if (!tmp)

0 commit comments

Comments
 (0)