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 Without limiting anything contained in the foregoing, this file, 15 which is part of C Driver for MySQL (Connector/C), is also subject to the 16 Universal FOSS Exception, version 1.0, a copy of which can be found at 17 http://oss.oracle.com/licenses/universal-foss-exception. 18 19 This program is distributed in the hope that it will be useful, 20 but WITHOUT ANY WARRANTY; without even the implied warranty of 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 GNU General Public License, version 2.0, for more details. 23 24 You should have received a copy of the GNU General Public License 25 along with this program; if not, write to the Free Software 26 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 27 28 /* 29 Data in little-endian format. 30 */ 31 32 #ifndef MY_BYTE_ORDER_ARCH_OPTIMIZED 33 #define float4get(V,M) memcpy(&V, (M), sizeof(float)) 34 #define float4store(V,M) memcpy(V, (&M), sizeof(float)) 35 #define float8get(V,M) doubleget((V),(M)) 36 #define float8store(V,M) doublestore((V),(M)) 37 38 /* Bi-endian hardware.... */ 39 #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) 40 #define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\ 41 *(((char*)T)+1)=(char) ((uchar *) &V)[5];\ 42 *(((char*)T)+2)=(char) ((uchar *) &V)[6];\ 43 *(((char*)T)+3)=(char) ((uchar *) &V)[7];\ 44 *(((char*)T)+4)=(char) ((uchar *) &V)[0];\ 45 *(((char*)T)+5)=(char) ((uchar *) &V)[1];\ 46 *(((char*)T)+6)=(char) ((uchar *) &V)[2];\ 47 *(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\ 48 while(0) 49 #define doubleget(V,M) do { double def_temp;\ 50 ((uchar*) &def_temp)[0]=(M)[4];\ 51 ((uchar*) &def_temp)[1]=(M)[5];\ 52 ((uchar*) &def_temp)[2]=(M)[6];\ 53 ((uchar*) &def_temp)[3]=(M)[7];\ 54 ((uchar*) &def_temp)[4]=(M)[0];\ 55 ((uchar*) &def_temp)[5]=(M)[1];\ 56 ((uchar*) &def_temp)[6]=(M)[2];\ 57 ((uchar*) &def_temp)[7]=(M)[3];\ 58 (V) = def_temp; } while(0) 59 #else /* Bi-endian hardware.... */ 60 61 /* Cast away type qualifiers (necessary as macro takes argument by value). */ 62 #define doublestore(T,V) memcpy((T), (void*) &V, sizeof(double)) 63 #define doubleget(V,M) memcpy(&V, (M), sizeof(double)) 64 65 #endif /* Bi-endian hardware.... */ 66 67 #endif /* !MY_BYTE_ORDER_ARCH_OPTIMIZED */ 68 69 #define ushortget(V,M) do { uchar *pM= (uchar*)(M);V = uint2korr(pM);} while(0) 70 #define shortget(V,M) do { uchar *pM= (uchar*)(M);V = sint2korr(pM);} while(0) 71 #define longget(V,M) do { uchar *pM= (uchar*)(M);V = sint4korr(pM);} while(0) 72 #define ulongget(V,M) do { uchar *pM= (uchar*)(M);V = uint4korr(pM);} while(0) 73 #define shortstore(T,V) int2store(T,V) 74 #define longstore(T,V) int4store(T,V) 75 76 #ifndef floatstore 77 /* Cast away type qualifiers (necessary as macro takes argument by value). */ 78 #define floatstore(T,V) memcpy((T), (void*) (&V), sizeof(float)) 79 #define floatget(V,M) memcpy(&V, (M), sizeof(float)) 80 #endif 81 82 #define longlongget(V,M) memcpy(&V, (M), sizeof(ulonglong)) 83 #define longlongstore(T,V) memcpy((T), &V, sizeof(ulonglong)) 84