blob: 731d6357fd2091242447660cab680974b54316f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
/* ISC license. */
#include <string.h>
#include <skalibs/stralloc.h>
void stralloc_reverse_blocks (stralloc *sa, size_t size)
{
size_t n = sa->len / (size << 1) ;
size_t i = 0 ;
char tmp[size] ;
for (; i < n ; i++)
{
size_t k = sa->len - (i + 1) * size ;
memcpy(tmp, sa->s + i * size, size) ;
memcpy(sa->s + i * size, sa->s + k, size) ;
memcpy(sa->s + k, tmp, size) ;
}
}
|