Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/klibc/kstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/klibc/kstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down