1 /* Copyright (c) 2012, 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, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 /* 24 Data in big-endian format. 25 */ 26 #define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\ 27 *((T)+1)=(char) ((uchar *) &A)[2];\ 28 *((T)+2)=(char) ((uchar *) &A)[1];\ 29 *((T)+3)=(char) ((uchar *) &A)[0]; } while(0) 30 31 #define float4get(V,M) do { float def_temp;\ 32 ((uchar*) &def_temp)[0]=(M)[3];\ 33 ((uchar*) &def_temp)[1]=(M)[2];\ 34 ((uchar*) &def_temp)[2]=(M)[1];\ 35 ((uchar*) &def_temp)[3]=(M)[0];\ 36 (V)=def_temp; } while(0) 37 38 #define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\ 39 *((T)+1)=(char) ((uchar *) &V)[6];\ 40 *((T)+2)=(char) ((uchar *) &V)[5];\ 41 *((T)+3)=(char) ((uchar *) &V)[4];\ 42 *((T)+4)=(char) ((uchar *) &V)[3];\ 43 *((T)+5)=(char) ((uchar *) &V)[2];\ 44 *((T)+6)=(char) ((uchar *) &V)[1];\ 45 *((T)+7)=(char) ((uchar *) &V)[0]; } while(0) 46 47 #define float8get(V,M) do { double def_temp;\ 48 ((uchar*) &def_temp)[0]=(M)[7];\ 49 ((uchar*) &def_temp)[1]=(M)[6];\ 50 ((uchar*) &def_temp)[2]=(M)[5];\ 51 ((uchar*) &def_temp)[3]=(M)[4];\ 52 ((uchar*) &def_temp)[4]=(M)[3];\ 53 ((uchar*) &def_temp)[5]=(M)[2];\ 54 ((uchar*) &def_temp)[6]=(M)[1];\ 55 ((uchar*) &def_temp)[7]=(M)[0];\ 56 (V) = def_temp; } while(0) 57 58 #define ushortget(V,M) do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\ 59 ((uint16) ((uint16) (M)[0]) << 8)); } while(0) 60 #define shortget(V,M) do { V = (short) (((short) ((uchar) (M)[1]))+\ 61 ((short) ((short) (M)[0]) << 8)); } while(0) 62 #define longget(V,M) do { int32 def_temp;\ 63 ((uchar*) &def_temp)[0]=(M)[0];\ 64 ((uchar*) &def_temp)[1]=(M)[1];\ 65 ((uchar*) &def_temp)[2]=(M)[2];\ 66 ((uchar*) &def_temp)[3]=(M)[3];\ 67 (V)=def_temp; } while(0) 68 #define ulongget(V,M) do { uint32 def_temp;\ 69 ((uchar*) &def_temp)[0]=(M)[0];\ 70 ((uchar*) &def_temp)[1]=(M)[1];\ 71 ((uchar*) &def_temp)[2]=(M)[2];\ 72 ((uchar*) &def_temp)[3]=(M)[3];\ 73 (V)=def_temp; } while(0) 74 #define shortstore(T,A) do { uint def_temp=(uint) (A) ;\ 75 *(((char*)T)+1)=(char)(def_temp); \ 76 *(((char*)T)+0)=(char)(def_temp >> 8); } while(0) 77 #define longstore(T,A) do { *(((char*)T)+3)=((A));\ 78 *(((char*)T)+2)=(((A) >> 8));\ 79 *(((char*)T)+1)=(((A) >> 16));\ 80 *(((char*)T)+0)=(((A) >> 24)); } while(0) 81 82 #define floatget(V,M) memcpy(&V, (M), sizeof(float)) 83 /* Cast away type qualifiers (necessary as macro takes argument by value). */ 84 #define floatstore(T,V) memcpy((T), (void*) (&V), sizeof(float)) 85 #define doubleget(V,M) memcpy(&V, (M), sizeof(double)) 86 /* Cast away type qualifiers (necessary as macro takes argument by value). */ 87 #define doublestore(T,V) memcpy((T), (void*) &V, sizeof(double)) 88 #define longlongget(V,M) memcpy(&V, (M), sizeof(ulonglong)) 89 #define longlongstore(T,V) memcpy((T), &V, sizeof(ulonglong)) 90