summaryrefslogtreecommitdiff
path: root/src/libstddjb/stralloc_reverse_blocks.c
blob: 86b7fc4cacdaaee143e9e628fa7404abcd805d85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* 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++)
  {
    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) ;
  }
}