// gnulliver.h - header information for the gnulliver library. // Copyright (C) 1994-2004 Paul Hardy // Copyright (C) 2011 Alan W. Irwin // // This file is part of the timeephem software project. // // timeephem is free software; you can redistribute it and/or modify // it under the terms of the GNU Library General Public License as published // by the Free Software Foundation; version 2 of the License. // // timeephem 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 Library General Public License for more details. // // You should have received a copy of the GNU Library General Public License // along with timeephem; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef __GNULLIVER_H__ #define __GNULLIVER_H__ // // Travels the middle of the road to swiftly gnullify // the Big-endian / Little-endian controversy. // Only works on machines with IEEE floating point. // // Swaps values between host order and network order without calls // to htonl(), etc. This is a symmetric conversion, so the same // function works in both directions. For example, to convert an // integer between host byte ordering and network byte ordering (in // either direction), use // // int i, j; // j = gnulliver32(i); // // then use j in an equation (if you just read i from the net), or // write j to the net (if i is an integer on your machine). // // The gnulliver routines work by setting a double to a certain value, // then examining a unioned byte array. // // The functions are: // // char gnulliver() - determine (or recalculate) endianness of host: // GNULLIVER_BIG, GNULLIVER_LITTLE, GNULLIVER_DEC // unsigned short gnulliver16(unsigned short input) // unsigned gnulliver32(unsigned input) // unsigned long gnulliver64(unsigned long input) // unsigned long long gnulliver128(unsigned long long input) // float gnulliver32f(float input) // double gnulliver64f(double input) // long double gnulliver128f(long double input) // // Set up for dealing with function visibility issues. #include "ephcomdll.h" #define GNULLIVER_VERSION "1.0" #define GNULLIVER_SWAP16 4 // Swap adjacent bytes in 2-byte string #define GNULLIVER_SWAP32 8 // Swap 2-byte pairs in 4-byte string #define GNULLIVER_SWAP64 16 // Swap 4-byte pairs in 8-byte string #define GNULLIVER_SWAP128 32 // Swap 8-byte pairs in 16-byte string // // What we have to do to convert between network (Big-Endian) order and // host machine order. // #define GNULLIVER_NATIVE 1 // No swapping regardless. #define GNULLIVER_BIG 2 // No swapping if this machine is Big-endian #define GNULLIVER_LITTLE ( GNULLIVER_SWAP16 | GNULLIVER_SWAP32 | GNULLIVER_SWAP64 | GNULLIVER_SWAP128 ) // This should work on a PDP-11 or VAX, but I have no way to test it. #define GNULLIVER_DEC ( GNULLIVER_SWAP32 | GNULLIVER_SWAP64 | GNULLIVER_SWAP128 ) // Public function declarations for the gnulliver library. GNULLIVERDLLIMPEXP unsigned char gnulliver(); GNULLIVERDLLIMPEXP unsigned short gnulliver16( unsigned short input ); GNULLIVERDLLIMPEXP unsigned gnulliver32( unsigned input ); GNULLIVERDLLIMPEXP unsigned long gnulliver64( unsigned long input ); GNULLIVERDLLIMPEXP unsigned char * gnulliver64c( unsigned char *ch ); GNULLIVERDLLIMPEXP unsigned long long gnulliver128( unsigned long long input ); GNULLIVERDLLIMPEXP float gnulliver32f( float input ); GNULLIVERDLLIMPEXP double gnulliver64f( double input ); GNULLIVERDLLIMPEXP long double gnulliver128f( long double input ); #endif // __GNULLIVER_H__