1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-15 17:43:51 +01:00

sys/string_utils: add reverse_buf()

This commit is contained in:
Benjamin Valentin 2025-03-19 16:45:55 +01:00
parent 785faa77f7
commit 1fdcaac52f
2 changed files with 19 additions and 0 deletions

View File

@ -179,6 +179,14 @@ ssize_t strscpy(char *dest, const char *src, size_t count);
*/
const void *memchk(const void *data, uint8_t c, size_t len);
/**
* @brief Reverse the order of bytes in a buffer
*
* @param[in, out] buf The buffer to reverse
* @param[in] len Size of the buffer
*/
void reverse_buf(void *buf, size_t len);
#ifdef __cplusplus
}
#endif

View File

@ -80,4 +80,15 @@ int __swprintf(string_writer_t *sw, FLASH_ATTR const char *restrict format, ...)
return res;
}
void reverse_buf(void *buf, size_t len)
{
uint8_t *cur = buf;
uint8_t *end = cur + len - 1;
while (cur < end) {
uint8_t tmp = *cur;
*cur++ = *end;
*end-- = tmp;
}
}
/** @} */