OSDN Git Service

First version
[st-ro/stro.git] / 3rdparty / mysql / include / big_endian.h
1 /* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
2
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; version 2 of the License.
6
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
16 #include <string.h>
17
18 /*
19   Data in big-endian format.
20 */
21 static inline void float4store(uchar  *T, float  A)
22 { *(T)= ((uchar *) &A)[3];
23   *((T)+1)=(char) ((uchar *) &A)[2];
24   *((T)+2)=(char) ((uchar *) &A)[1];
25   *((T)+3)=(char) ((uchar *) &A)[0]; }
26
27 static inline void float4get  (float  *V, const uchar *M)
28 { float def_temp;
29   ((uchar*) &def_temp)[0]=(M)[3];
30   ((uchar*) &def_temp)[1]=(M)[2];
31   ((uchar*) &def_temp)[2]=(M)[1];
32   ((uchar*) &def_temp)[3]=(M)[0];
33   (*V)=def_temp; }
34
35 static inline void float8store(uchar  *T, double V)
36 { *(T)= ((uchar *) &V)[7];
37   *((T)+1)=(char) ((uchar *) &V)[6];
38   *((T)+2)=(char) ((uchar *) &V)[5];
39   *((T)+3)=(char) ((uchar *) &V)[4];
40   *((T)+4)=(char) ((uchar *) &V)[3];
41   *((T)+5)=(char) ((uchar *) &V)[2];
42   *((T)+6)=(char) ((uchar *) &V)[1];
43   *((T)+7)=(char) ((uchar *) &V)[0]; }
44
45 static inline void float8get  (double *V, const uchar *M)
46 { double def_temp;
47   ((uchar*) &def_temp)[0]=(M)[7];                                 
48   ((uchar*) &def_temp)[1]=(M)[6];
49   ((uchar*) &def_temp)[2]=(M)[5];
50   ((uchar*) &def_temp)[3]=(M)[4];
51   ((uchar*) &def_temp)[4]=(M)[3];
52   ((uchar*) &def_temp)[5]=(M)[2];
53   ((uchar*) &def_temp)[6]=(M)[1];
54   ((uchar*) &def_temp)[7]=(M)[0];
55   (*V) = def_temp; }
56
57 static inline void ushortget(uint16 *V, const uchar *pM)
58 { *V = (uint16) (((uint16) ((uchar) (pM)[1]))+
59                  ((uint16) ((uint16) (pM)[0]) << 8)); }
60 static inline void shortget (int16  *V, const uchar *pM)
61 { *V = (short) (((short) ((uchar) (pM)[1]))+
62                 ((short) ((short) (pM)[0]) << 8)); }
63 static inline void longget  (int32  *V, const uchar *pM)
64 { int32 def_temp;
65   ((uchar*) &def_temp)[0]=(pM)[0];
66   ((uchar*) &def_temp)[1]=(pM)[1];
67   ((uchar*) &def_temp)[2]=(pM)[2];
68   ((uchar*) &def_temp)[3]=(pM)[3];
69   (*V)=def_temp; }
70 static inline void ulongget (uint32 *V, const uchar *pM)
71 { uint32 def_temp;
72   ((uchar*) &def_temp)[0]=(pM)[0];
73   ((uchar*) &def_temp)[1]=(pM)[1];
74   ((uchar*) &def_temp)[2]=(pM)[2];
75   ((uchar*) &def_temp)[3]=(pM)[3];
76   (*V)=def_temp; }
77 static inline void shortstore(uchar *T, int16 A)
78 { uint def_temp=(uint) (A) ;
79   *(((char*)T)+1)=(char)(def_temp);
80   *(((char*)T)+0)=(char)(def_temp >> 8); }
81 static inline void longstore (uchar *T, int32 A)
82 { *(((char*)T)+3)=((A));
83   *(((char*)T)+2)=(((A) >> 8));
84   *(((char*)T)+1)=(((A) >> 16));
85   *(((char*)T)+0)=(((A) >> 24)); }
86
87 static inline void floatget(float *V, const uchar *M)
88 {
89   memcpy(V, (M), sizeof(float));
90 }
91
92 static inline void floatstore(uchar *T, float V)
93 {
94   memcpy((T), (&V), sizeof(float));
95 }
96
97 static inline void doubleget(double *V, const uchar *M)
98 {
99   memcpy(V, (M), sizeof(double));
100 }
101
102 static inline void doublestore(uchar *T, double V)
103 {
104   memcpy((T), &V, sizeof(double));
105 }
106
107 static inline void longlongget(longlong *V, const uchar *M)
108 {
109   memcpy(V, (M), sizeof(ulonglong));
110 }
111 static inline void longlongstore(uchar *T, longlong V)
112 {
113   memcpy((T), &V, sizeof(ulonglong));
114 }