diff --git a/include/klibc/kstring.h b/include/klibc/kstring.h index c91277f3244..84fd49b96cd 100644 --- a/include/klibc/kstring.h +++ b/include/klibc/kstring.h @@ -31,7 +31,7 @@ char *rt_strncpy(char *dest, const char *src, size_t n); int rt_strncmp(const char *cs, const char *ct, size_t count); int rt_strcmp(const char *cs, const char *ct); size_t rt_strlen(const char *src); - +int rt_atoi(const char* s); #ifdef __cplusplus } #endif diff --git a/src/klibc/kstring.c b/src/klibc/kstring.c index b6d553ffa34..feae0507bef 100644 --- a/src/klibc/kstring.c +++ b/src/klibc/kstring.c @@ -533,6 +533,23 @@ size_t rt_strnlen(const char *s, size_t maxlen) #endif /* RT_KLIBC_USING_USER_STRNLEN */ RTM_EXPORT(rt_strnlen); +int rt_atoi(const char* s) +{ + int n = 0, sign = 1; + + if (*s == '-') + { + sign = -1; + s++; + } + else if (*s == '+') + s++; + + while (*s >= '0' && *s <= '9') n = n * 10 + (*s++ - '0'); + + return sign * n; +} + #ifdef RT_USING_HEAP /** * @brief This function will duplicate a string.