~javier-lopez/ubuntu/quantal/cdo/sru-1023329

« back to all changes in this revision

Viewing changes to libcdi/src/swap.c

  • Committer: Bazaar Package Importer
  • Author(s): Alastair McKinstry
  • Date: 2010-09-22 15:58:09 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100922155809-u1d3vlmlqj02uxjt
Tags: 1.4.6.dfsg.1-1
New upstream release. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if defined (HAVE_CONFIG_H)
 
2
#  include "config.h"
 
3
#endif
 
4
 
 
5
#include <stdio.h>
 
6
 
 
7
#include "error.h"
 
8
#include "binary.h"
 
9
 
 
10
void swap4byte(void *ptr, size_t size)
 
11
{
 
12
  static const char *func = "swap4byte";
 
13
  INT32 *ptrtmp;
 
14
  int nval;
 
15
 
 
16
  nval = size;
 
17
  if ( nval < 0 ) nval = 0;
 
18
  ptrtmp = (INT32 *) ptr;
 
19
 
 
20
  if ( sizeof(INT32) == 4 )
 
21
    {
 
22
      while ( nval-- )
 
23
        {
 
24
          *ptrtmp = (((*ptrtmp >> 24) & 0x00ff) | ((*ptrtmp & 0x00ff) << 24) |
 
25
                     ((*ptrtmp >>  8) & 0xff00) | ((*ptrtmp & 0xff00) <<  8));
 
26
          ptrtmp++;
 
27
        }
 
28
    }
 
29
  else
 
30
    {
 
31
      Error(func, "not implemented for %d byte data", sizeof(INT32));
 
32
    }
 
33
}
 
34
 
 
35
void swap8byte(void *ptr, size_t size)
 
36
{
 
37
  static const char *func = "swap8byte";
 
38
  INT64 *ptrtmp;
 
39
  int nval;
 
40
 
 
41
  nval = size;
 
42
  if ( nval < 0 ) nval = 0;
 
43
  ptrtmp = (INT64 *) ptr;
 
44
 
 
45
  if ( sizeof(INT64) == 8 )
 
46
    {
 
47
      while ( nval-- )
 
48
        {
 
49
          *ptrtmp = (((*ptrtmp >> 56) & 0x000000ff) | ((*ptrtmp & 0x000000ff) << 56) |
 
50
                     ((*ptrtmp >> 40) & 0x0000ff00) | ((*ptrtmp & 0x0000ff00) << 40) |
 
51
                     ((*ptrtmp >> 24) & 0x00ff0000) | ((*ptrtmp & 0x00ff0000) << 24) |
 
52
                     ((*ptrtmp >>  8) & 0xff000000) | ((*ptrtmp & 0xff000000) <<  8));
 
53
          ptrtmp++;
 
54
        }
 
55
    }
 
56
  else
 
57
    {
 
58
      Error(func, "not implemented for %d byte data", sizeof(INT64));
 
59
    }
 
60
}