TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcmisc
swap.c
Go to the documentation of this file.
1
5
/*****************************************************************************/
6
#include "
libtpcmisc.h
"
7
/*****************************************************************************/
8
9
/*****************************************************************************/
14
int
little_endian
()
15
{
16
int
x=1;
17
if
(*(
char
*)&x==1)
return
(1);
else
return
(0);
18
}
19
/*****************************************************************************/
20
21
/*****************************************************************************/
31
void
swap
(
void
*from,
void
*to,
int
size) {
32
unsigned
char
c;
33
unsigned
short
int
s;
34
unsigned
long
l;
35
36
switch
(size) {
37
case
1:
38
*(
char
*)to=*(
char
*)from;
39
break
;
40
case
2:
41
c=*(
unsigned
char
*)from;
42
*(
unsigned
char
*)to = *((
unsigned
char
*)from+1);
43
*((
unsigned
char
*)to+1) = c;
44
/*swab(from, to, size); // NOT ANSI */
45
break
;
46
case
4:
47
s=*(
unsigned
short
*)from;
48
*(
unsigned
short
*)to = *((
unsigned
short
*)from+1);
49
*((
unsigned
short
*)to+1) = s;
50
swap
((
char
*)to, (
char
*)to, 2);
51
swap
((
char
*)((
unsigned
short
*)to+1), (
char
*)((
unsigned
short
*)to+1), 2);
52
break
;
53
case
8:
54
l=*(
unsigned
long
*)from;
55
*(
unsigned
long
*)to = *((
unsigned
long
*)from+1);
56
*((
unsigned
long
*)to+1) = l;
57
swap
((
char
*)to, (
char
*)to, 4);
58
swap
((
char
*)((
unsigned
long
*)to+1), (
char
*)((
unsigned
long
*)to+1), 4);
59
break
;
60
}
61
}
62
/*****************************************************************************/
63
64
/*****************************************************************************/
72
void
swabip
(
73
void
*buf,
long
long
int
size
74
) {
75
unsigned
char
c;
76
77
for
(
long
long
i=1; i<size; i+=2) {
78
c=*((
unsigned
char
*)buf+i);
79
*((
unsigned
char
*)buf+i)=*((
unsigned
char
*)buf+(i-1));
80
*((
unsigned
char
*)buf+(i-1))=c;
81
}
82
}
83
/*****************************************************************************/
84
85
/*****************************************************************************/
93
void
swawbip
(
94
void
*buf,
long
long
int
size
95
) {
96
unsigned
char
c, *cptr;
97
98
cptr=(
unsigned
char
*)buf;
99
for
(
long
long
i=0; i<size; i+=4, cptr+=4) {
100
c=cptr[0]; cptr[0]=cptr[3]; cptr[3]=c;
101
c=cptr[1]; cptr[1]=cptr[2]; cptr[2]=c;
102
}
103
}
104
/*****************************************************************************/
105
106
/*****************************************************************************/
114
void
swawip
(
115
void
*buf,
long
long
int
size
116
) {
117
unsigned
short
int
s, *sptr;
118
119
sptr=(
unsigned
short
int
*)buf;
120
for
(
long
long
i=0; i<size; i+=4, sptr+=2) {
121
s=sptr[0]; sptr[0]=sptr[1]; sptr[1]=s;
122
}
123
}
124
/*****************************************************************************/
125
126
/*****************************************************************************/
133
void
printf32bits
(
void
*buf) {
134
unsigned
int
u, i;
135
int
j;
136
137
memcpy(&u, buf, 4);
138
for
(i=32; i>0; i--) {
139
j=i-1;
if
(i<32 && (i%8)==0) printf(
" "
);
140
if
(u & (1L<<j)) printf(
"1"
);
else
printf(
"0"
);
141
}
142
printf(
"\n"
);
143
}
144
/*****************************************************************************/
145
146
/*****************************************************************************/
147
libtpcmisc.h
Header file for libtpcmisc.
swawip
void swawip(void *buf, long long int size)
Definition
swap.c:114
swabip
void swabip(void *buf, long long int size)
Definition
swap.c:72
swawbip
void swawbip(void *buf, long long int size)
Definition
swap.c:93
printf32bits
void printf32bits(void *buf)
Definition
swap.c:133
little_endian
int little_endian()
Definition
swap.c:14
swap
void swap(void *from, void *to, int size)
Definition
swap.c:31
Generated on
for TPCCLIB by
1.17.0