X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsupport%2Ffnetorderstream.cpp;h=57bcb46cc4752bc7bc357c3444bd4a3476221a9c;hp=41d1ead4e27c29e8f251a16b7f7429767dc600de;hb=f7ee98f7d964ed361068179f0e7ea4475ed1abdf;hpb=c00c639073653fac7463a88f2b000f263236550d diff --git a/libctsupport/fnetorderstream.cpp b/libctsupport/fnetorderstream.cpp index 41d1ead..57bcb46 100644 --- a/libctsupport/fnetorderstream.cpp +++ b/libctsupport/fnetorderstream.cpp @@ -1,3 +1,23 @@ +/***************************************************************************** +** This is part of the CTSim program +** Copyright (c) 1983-2001 Kevin Rosenberg +** +** $Id$ +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License (version 2) as +** published by the Free Software Foundation. +** +** 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + #if HAVE_CONFIG_H #include "config.h" #endif @@ -10,42 +30,42 @@ #include "fnetorderstream.h" -void +void ConvertNetworkOrder (void* buffer, size_t bytes) { #ifndef WORDS_BIGENDIAN if (bytes < 2) - return; + return; char* start = static_cast(buffer); char* end = start + bytes - 1; // last byte size_t nSwap = bytes / 2; - + while (nSwap-- > 0) { - unsigned char c = *start; - *start++ = *end; - *end-- = c; + unsigned char c = *start; + *start++ = *end; + *end-- = c; } -#endif +#endif } -void +void ConvertReverseNetworkOrder (void* buffer, size_t bytes) { #ifdef WORDS_BIGENDIAN if (bytes < 2) - return; + return; char* start = static_cast(buffer); - char* end = start + bytes - 1; // last byte + char* end = start + bytes - 1; // last byte size_t nSwap = bytes / 2; - + while (nSwap-- > 0) { - unsigned char c = *start; - *start++ = *end; - *end-- = c; + unsigned char c = *start; + *start++ = *end; + *end-- = c; } -#endif +#endif } void @@ -130,7 +150,7 @@ frnetorderstream::writeInt32 (kuint32 n) { write (reinterpret_cast(&n), 4); } -void +void frnetorderstream::writeFloat32 (kfloat32 n) { #ifdef WORDS_BIGENDIAN SwapBytes4 (&n); @@ -138,7 +158,7 @@ frnetorderstream::writeFloat32 (kfloat32 n) { write (reinterpret_cast(&n), 4); } -void +void frnetorderstream::writeFloat64 (kfloat64 n) { #ifdef WORDS_BIGENDIAN SwapBytes8 (&n); @@ -146,7 +166,7 @@ frnetorderstream::writeFloat64 (kfloat64 n) { write (reinterpret_cast(&n), 8); } -void +void frnetorderstream::readInt16 (kuint16& n) { read (reinterpret_cast(&n), 2); #ifdef WORDS_BIGENDIAN @@ -154,7 +174,7 @@ frnetorderstream::readInt16 (kuint16& n) { #endif } -void +void frnetorderstream::readInt32 (kuint32& n) { read (reinterpret_cast(&n), 4); #ifdef WORDS_BIGENDIAN