Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
577bd1cc
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
577bd1cc
编写于
10月 13, 2021
作者:
B
Bernard Xiong
提交者:
GitHub
10月 13, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5149 from mysterywolf/strnlen
fixed bug #5138
上级
98404184
66399189
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
25 deletion
+35
-25
include/rtthread.h
include/rtthread.h
+10
-5
src/kservice.c
src/kservice.c
+25
-20
未找到文件。
include/rtthread.h
浏览文件 @
577bd1cc
...
...
@@ -564,6 +564,7 @@ int __rt_ffs(int value);
void
*
rt_memset
(
void
*
src
,
int
c
,
rt_ubase_t
n
);
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
);
...
...
@@ -573,7 +574,6 @@ 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
);
rt_int32_t
rt_strcmp
(
const
char
*
cs
,
const
char
*
ct
);
rt_size_t
rt_strnlen
(
const
char
*
s
,
rt_ubase_t
maxlen
);
rt_size_t
rt_strlen
(
const
char
*
src
);
#else
#include <string.h>
...
...
@@ -584,15 +584,20 @@ rt_size_t rt_strlen(const char *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)
#define rt_strnlen(s, maxlen) strnlen(s, maxlen)
#define rt_strlen(src) strlen(src)
#endif
/*RT_KSERVICE_USING_STDLIB*/
char
*
rt_strdup
(
const
char
*
s
);
#if !defined(RT_KSERVICE_USING_STDLIB) || defined(__ARMCC_VERSION)
rt_size_t
rt_strnlen
(
const
char
*
s
,
rt_ubase_t
maxlen
);
#else
#define rt_strnlen(s, maxlen) strnlen(s, maxlen)
#endif
/* !defined(RT_KSERVICE_USING_STDLIB) || defined(__ARMCC_VERSION) */
#ifdef __ARMCC_VERSION
/*
lack strdup interface
*/
/*
MDK doesn't have these APIs
*/
char
*
strdup
(
const
char
*
str
);
#endif
size_t
strnlen
(
const
char
*
s
,
size_t
maxlen
);
#endif
/* __ARMCC_VERSION */
void
rt_show_version
(
void
);
...
...
src/kservice.c
浏览文件 @
577bd1cc
...
...
@@ -500,49 +500,54 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct)
RTM_EXPORT
(
rt_strcmp
);
/**
* The strnlen() function returns the number of characters in the
* string pointed to by s, excluding the terminating null byte ('\0'),
* but at most maxlen. In doing this, strnlen() looks only at the
* first maxlen characters in the string pointed to by s and never
* beyond s+maxlen.
*
* @param s is the string.
* This function will return the length of a string, which terminate will
* null character.
*
* @param
maxlen is the max size.
* @param
s is the string
*
* @return The length of string.
*/
rt_size_t
rt_str
nlen
(
const
char
*
s
,
rt_ubase_t
maxlen
)
rt_size_t
rt_str
len
(
const
char
*
s
)
{
const
char
*
sc
;
for
(
sc
=
s
;
*
sc
!=
'\0'
&&
(
rt_ubase_t
)(
sc
-
s
)
<
maxlen
;
++
sc
)
/* nothing */
for
(
sc
=
s
;
*
sc
!=
'\0'
;
++
sc
)
/* nothing */
;
return
sc
-
s
;
}
RTM_EXPORT
(
rt_str
n
len
);
RTM_EXPORT
(
rt_strlen
);
#endif
/* RT_KSERVICE_USING_STDLIB */
#if !defined(RT_KSERVICE_USING_STDLIB) || defined(__ARMCC_VERSION)
/**
* This function will return the length of a string, which terminate will
* null character.
* The strnlen() function returns the number of characters in the
* string pointed to by s, excluding the terminating null byte ('\0'),
* but at most maxlen. In doing this, strnlen() looks only at the
* first maxlen characters in the string pointed to by s and never
* beyond s+maxlen.
*
* @param s is the string
* @param s is the string.
*
* @param maxlen is the max size.
*
* @return The length of string.
*/
rt_size_t
rt_str
len
(
const
char
*
s
)
rt_size_t
rt_str
nlen
(
const
char
*
s
,
rt_ubase_t
maxlen
)
{
const
char
*
sc
;
for
(
sc
=
s
;
*
sc
!=
'\0'
;
++
sc
)
/* nothing */
for
(
sc
=
s
;
*
sc
!=
'\0'
&&
(
rt_ubase_t
)(
sc
-
s
)
<
maxlen
;
++
sc
)
/* nothing */
;
return
sc
-
s
;
}
RTM_EXPORT
(
rt_strlen
);
#endif
/* RT_KSERVICE_USING_STDLIB */
RTM_EXPORT
(
rt_strnlen
);
#ifdef __ARMCC_VERSION
size_t
strnlen
(
const
char
*
s
,
size_t
maxlen
)
__attribute__
((
alias
(
"rt_strnlen"
)));
#endif
/* __ARMCC_VERSION */
#endif
/* !defined(RT_KSERVICE_USING_STDLIB) || defined(__ARMCC_VERSION) */
#ifdef RT_USING_HEAP
/**
...
...
@@ -567,7 +572,7 @@ char *rt_strdup(const char *s)
RTM_EXPORT
(
rt_strdup
);
#ifdef __ARMCC_VERSION
char
*
strdup
(
const
char
*
s
)
__attribute__
((
alias
(
"rt_strdup"
)));
#endif
#endif
/* __ARMCC_VERSION */
#endif
/* RT_USING_HEAP */
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录