summaryrefslogtreecommitdiff
path: root/src/libstddjb/stralloc_reverse_blocks.c
blob: 67a18de0fb721ba7cc042c4c8874b60ad5fe3ece (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* ISC license. */

#include <sys/types.h>
#include <string.h>
#include <skalibs/stralloc.h>

void stralloc_reverse_blocks (stralloc *sa, size_t size)
{
  register size_t n = sa->len / (size << 1) ;
  register size_t i = 0 ;
  char tmp[size] ;
  for (; i < n ; i++)
  {
    memcpy(tmp, sa->s + i * size, size) ;
    memcpy(sa->s + i * size, sa->s + (2*n - 1 - i) * size, size) ;
    memcpy(sa->s + (2*n - 1 - i) * size, tmp, size) ;
  }
}