FreeBASIC  0.91.0
swap_mem.c
Go to the documentation of this file.
1 /* swap for non-strings */
2 
3 #include "fb.h"
4 
5 FBCALL void fb_MemSwap( unsigned char *dst, unsigned char *src, ssize_t bytes )
6 {
7  ssize_t i;
8  unsigned int ti;
9  unsigned char tb;
10 
11  if( (dst == NULL) || (src == NULL) || (bytes <= 0) )
12  return;
13 
14  FB_LOCK();
15 
16  /* words */
17  for( i = 0; i < (bytes >> 2); i++ )
18  {
19  ti = *(unsigned int *)src;
20  *(unsigned int *)src = *(unsigned int *)dst;
21  *(unsigned int *)dst = ti;
22 
23  src += sizeof(unsigned int);
24  dst += sizeof(unsigned int);
25  }
26 
27  /* remainder */
28  for( i = 0; i < (bytes & 3); i++ )
29  {
30  tb = *src;
31  *src++ = *dst;
32  *dst++ = tb;
33  }
34 
35  FB_UNLOCK();
36 }