mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-15 09:33:50 +01:00
sys/string_utils: add memchk()
Check if all bytes in a buffer are set to s certain value - inverse of memset().
This commit is contained in:
parent
23790a3f52
commit
c57b13f1e8
@ -91,6 +91,18 @@ static inline void explicit_bzero(void *dest, size_t n_bytes)
|
||||
*/
|
||||
ssize_t strscpy(char *dest, const char *src, size_t count);
|
||||
|
||||
/**
|
||||
* @brief Check if the entire buffer is filled with the same byte.
|
||||
*
|
||||
* @param[in] data The buffer to probe
|
||||
* @param[in] c The byte to check of
|
||||
* @param[in] len Size of the buffer
|
||||
*
|
||||
* @return NULL if the entire buffer is filled with @p c
|
||||
* @return pointer to the first non-matching byte
|
||||
*/
|
||||
const void *memchk(const void *data, uint8_t c, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -37,4 +37,17 @@ ssize_t strscpy(char *dest, const char *src, size_t count)
|
||||
return -E2BIG;
|
||||
}
|
||||
}
|
||||
|
||||
const void *memchk(const void *data, uint8_t c, size_t len)
|
||||
{
|
||||
const uint8_t *end = (uint8_t *)data + len;
|
||||
for (const uint8_t *d = data; d != end; ++d) {
|
||||
if (c != *d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user