/***************************** {{{ LICENSE ********************************\ * dbobj, the relational object persistence module for PHP * * Copyright (C) 2006 Adam Banko * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * \***************************** LICENSE }}} ********************************/ #ifndef DBOBJ_BYTEORDER_H #define DBOBJ_BYTEORDER_H #ifdef WORDS_BIGENDIAN //short #define htons(x) (x) #define ntohs(x) (x) //long #define htonl(x) (x) #define ntohl(x) (x) //float #define htonf(x) (x) #define ntohf(x) (x) //double #define htond(x) (x) #define ntohd(x) (x) #else //WORDS_BIGENDIAN #ifdef PHP_WIN32 # ifndef WINNT # define WINNT 1 # endif #endif /*PHP_WIN32*/ #include #ifndef htonf union float_long { float f; long l; }; inline static float htonf(float x) { union float_long fl; fl.f = x; fl.l = htonl(fl.l); return fl.f; } inline static float ntohf(float x) { union float_long fl; fl.f = x; fl.l = htonl(fl.l); return fl.f; } #endif //htonf #ifndef htond //if defined(LINUX) #ifdef LINUX #include #define htond(x) __arch__swab64(x) #define ntohd(x) __arch__swab64(x) #else //!defined(LINUX) inline static double safe_swab64(double in) { double out; char *inP = (char*)∈ char *outP = ((char*)&out) + sizeof(double); int i; for(i=0; i< sizeof(double); i++) { *(inP++) = *--outP; } return out; } #define htond(x) safe_swab64(x) #define ntohd(x) safe_swab64(x) #endif //!defined(LINUX) #endif //htond #endif //WORDS_BIGENDIAN #endif //DBOBJ_BYTEORDER_H /* * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */