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:
parent
785faa77f7
commit
1fdcaac52f
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user