1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

fmt: Add fmt_strnlen function

This commit is contained in:
Koen Zandberg 2018-06-14 10:48:44 +02:00
parent e91e0a7807
commit 1778dbde85
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B
2 changed files with 20 additions and 0 deletions

View File

@ -83,6 +83,15 @@ size_t fmt_strlen(const char *str)
return (tmp - str);
}
size_t fmt_strnlen(const char *str, size_t maxlen)
{
const char *tmp = str;
while(*tmp && maxlen--) {
tmp++;
}
return (tmp - str);
}
size_t fmt_str(char *out, const char *str)
{
int len = 0;

View File

@ -294,6 +294,17 @@ size_t fmt_float(char *out, float f, unsigned precision);
*/
size_t fmt_strlen(const char *str);
/**
* @brief Count at most @p maxlen characters until '\0' (exclusive) in @p str
*
* @param[in] str Pointer to string
* @param[in] maxlen Maximum number of chars to count
*
* @return nr of characters in string @p str points to, or @p maxlen if no
* null terminator is found within @p maxlen chars
*/
size_t fmt_strnlen(const char *str, size_t maxlen);
/**
* @brief Copy null-terminated string (excluding terminating \0)
*