From 65ac4a081070dd51553b1aea3cfb784ac0290d47 Mon Sep 17 00:00:00 2001 From: zhangjun <2281979437@qq.com> Date: Fri, 12 Aug 2016 22:14:07 +0800 Subject: 增加rt_strnlen,lua采用单独的线程 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kservice.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 7250639346..f5cd934e2d 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -462,7 +462,26 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct) return (*cs - *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 the string + * @param maxlen the max size + * @return the length of string + */ +rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen) +{ + const char *sc; + + for (sc = s; *sc != '\0' && sc - s < maxlen; ++sc) /* nothing */ + ; + return sc - s; +} /** * This function will return the length of a string, which terminate will * null character. -- cgit v1.3.1