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:
parent
e91e0a7807
commit
1778dbde85
@ -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)
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user