diff options
| author | Bernard Xiong <[email protected]> | 2021-10-13 15:39:19 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-13 15:39:19 +0800 |
| commit | 577bd1cc7c2b91e47ef0680020ee5f1c2b5260a3 (patch) | |
| tree | b6ed7ada50b6cdd8f218ede6356f2a7cc1aaf3be /src/kservice.c | |
| parent | 98404184b1d84da5464f00c04d1ca92fe2216261 (diff) | |
| parent | 663991897bbd2ae20098747fd79c57e0d42c70c0 (diff) | |
Merge pull request #5149 from mysterywolf/strnlen
fixed bug #5138
Diffstat (limited to 'src/kservice.c')
| -rw-r--r-- | src/kservice.c | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/kservice.c b/src/kservice.c index 41d81d8677..cc1dc6e22c 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -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_strnlen(const char *s, rt_ubase_t maxlen) +rt_size_t rt_strlen(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_strnlen); +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_strlen(const char *s) +rt_size_t rt_strnlen(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 */ /** |
