Sfoglia il codice sorgente

[kservice] Update the rt_strnlen function.

armink 6 anni fa
parent
commit
b2c338970f
2 ha cambiato i file con 5 aggiunte e 1 eliminazioni
  1. 1 0
      include/rtthread.h
  2. 4 1
      src/kservice.c

+ 1 - 0
include/rtthread.h

@@ -516,6 +516,7 @@ void *rt_memcpy(void *dest, const void *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_strlen(const char *src);
+rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen);
 char *rt_strdup(const char *s);
 #if defined(__CC_ARM) || defined(__CLANG_ARM)
 /* leak strdup interface */

+ 4 - 1
src/kservice.c

@@ -461,6 +461,7 @@ 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'),
@@ -476,11 +477,13 @@ rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen)
 {
     const char *sc;
 
-    for (sc = s; *sc != '\0' && sc - s < (int)maxlen; ++sc) /* nothing */
+    for (sc = s; *sc != '\0' && (rt_ubase_t)(sc - s) < maxlen; ++sc) /* nothing */
         ;
 
     return sc - s;
 }
+RTM_EXPORT(rt_strnlen);
+
 /**
  * This function will return the length of a string, which terminate will
  * null character.