Skip to content
Snippets Groups Projects
Unverified Commit 1778dbde authored by Koen Zandberg's avatar Koen Zandberg
Browse files

fmt: Add fmt_strnlen function

parent e91e0a78
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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)
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment