mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-01 01:01:03 +00:00
Improved byte swapping stuff for 64-bit clean operation.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3671 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ac2db6c7d9
commit
d46086fbc3
5 changed files with 258 additions and 114 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Mon Feb 8 10:05:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
* Source/include/NSByteOrder.h: Implemented a full set of byte-swapping
|
||||||
|
inline functions for integers with known sizes.
|
||||||
|
* Source/NSData.m: Corrected serialization/deserialization routines to
|
||||||
|
do byte-swapping using new functions.
|
||||||
|
* Source/UnixFileHandle.m: Use new byte-swapping functions rather than
|
||||||
|
htonl(), htons(), ntohl(), ntohs().
|
||||||
|
* Source/NSUnarchiver.m: Use new byte-swapping functions.
|
||||||
|
|
||||||
1999-02-04 Adam Fedor <fedor@gnu.org>
|
1999-02-04 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
||||||
* config/config.printf.c: New file.
|
* config/config.printf.c: New file.
|
||||||
|
|
|
@ -57,6 +57,42 @@ GSSwapI64(gsu64 in) __attribute__((unused));
|
||||||
static inline gsu128
|
static inline gsu128
|
||||||
GSSwapI128(gsu128 in) __attribute__((unused));
|
GSSwapI128(gsu128 in) __attribute__((unused));
|
||||||
|
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapBigI16ToHost(gsu16 in) __attribute__((unused));
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapBigI32ToHost(gsu32 in) __attribute__((unused));
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapBigI64ToHost(gsu64 in) __attribute__((unused));
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapBigI128ToHost(gsu128 in) __attribute__((unused));
|
||||||
|
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapHostI16ToBig(gsu16 in) __attribute__((unused));
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapHostI32ToBig(gsu32 in) __attribute__((unused));
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapHostI64ToBig(gsu64 in) __attribute__((unused));
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapHostI128ToBig(gsu128 in) __attribute__((unused));
|
||||||
|
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapLittleI16ToHost(gsu16 in) __attribute__((unused));
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapLittleI32ToHost(gsu32 in) __attribute__((unused));
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapLittleI64ToHost(gsu64 in) __attribute__((unused));
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapLittleI128ToHost(gsu128 in) __attribute__((unused));
|
||||||
|
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapHostI16ToLittle(gsu16 in) __attribute__((unused));
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapHostI32ToLittle(gsu32 in) __attribute__((unused));
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapHostI64ToLittle(gsu64 in) __attribute__((unused));
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapHostI128ToLittle(gsu128 in) __attribute__((unused));
|
||||||
|
|
||||||
|
|
||||||
static inline gsu16
|
static inline gsu16
|
||||||
GSSwapI16(gsu16 in)
|
GSSwapI16(gsu16 in)
|
||||||
|
@ -395,6 +431,27 @@ NSHostByteOrder(void)
|
||||||
/*
|
/*
|
||||||
* Swap Big endian to host
|
* Swap Big endian to host
|
||||||
*/
|
*/
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapBigI16ToHost(gsu16 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapBigI32ToHost(gsu32 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapBigI64ToHost(gsu64 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapBigI128ToHost(gsu128 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
static inline double
|
static inline double
|
||||||
NSSwapBigDoubleToHost(NSSwappedDouble num)
|
NSSwapBigDoubleToHost(NSSwappedDouble num)
|
||||||
{
|
{
|
||||||
|
@ -434,6 +491,27 @@ NSSwapBigShortToHost(unsigned short num)
|
||||||
/*
|
/*
|
||||||
* Swap Host to Big endian
|
* Swap Host to Big endian
|
||||||
*/
|
*/
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapHostI16ToBig(gsu16 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapHostI32ToBig(gsu32 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapHostI64ToBig(gsu64 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapHostI128ToBig(gsu128 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
static inline NSSwappedDouble
|
static inline NSSwappedDouble
|
||||||
NSSwapHostDoubleToBig(double num)
|
NSSwapHostDoubleToBig(double num)
|
||||||
{
|
{
|
||||||
|
@ -473,6 +551,27 @@ NSSwapHostShortToBig(unsigned short num)
|
||||||
/*
|
/*
|
||||||
* Swap Little endian to Host
|
* Swap Little endian to Host
|
||||||
*/
|
*/
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapLittleI16ToHost(gsu16 in)
|
||||||
|
{
|
||||||
|
return GSSwapI16(in);
|
||||||
|
}
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapLittleI32ToHost(gsu32 in)
|
||||||
|
{
|
||||||
|
return GSSwapI32(in);
|
||||||
|
}
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapLittleI64ToHost(gsu64 in)
|
||||||
|
{
|
||||||
|
return GSSwapI64(in);
|
||||||
|
}
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapLittleI128ToHost(gsu128 in)
|
||||||
|
{
|
||||||
|
return GSSwapI128(in);
|
||||||
|
}
|
||||||
|
|
||||||
static inline double
|
static inline double
|
||||||
NSSwapLittleDoubleToHost(NSSwappedDouble num)
|
NSSwapLittleDoubleToHost(NSSwappedDouble num)
|
||||||
{
|
{
|
||||||
|
@ -512,6 +611,27 @@ NSSwapLittleShortToHost(unsigned short num)
|
||||||
/*
|
/*
|
||||||
* Swap Host to Little endian
|
* Swap Host to Little endian
|
||||||
*/
|
*/
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapHostI16ToLittle(gsu16 in)
|
||||||
|
{
|
||||||
|
return GSSwapI16(in);
|
||||||
|
}
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapHostI32ToLittle(gsu32 in)
|
||||||
|
{
|
||||||
|
return GSSwapI32(in);
|
||||||
|
}
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapHostI64ToLittle(gsu64 in)
|
||||||
|
{
|
||||||
|
return GSSwapI64(in);
|
||||||
|
}
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapHostI128ToLittle(gsu128 in)
|
||||||
|
{
|
||||||
|
return GSSwapI128(in);
|
||||||
|
}
|
||||||
|
|
||||||
static inline NSSwappedDouble
|
static inline NSSwappedDouble
|
||||||
NSSwapHostDoubleToLittle(double num)
|
NSSwapHostDoubleToLittle(double num)
|
||||||
{
|
{
|
||||||
|
@ -561,6 +681,26 @@ NSHostByteOrder(void)
|
||||||
/*
|
/*
|
||||||
* Swap Big endian to host
|
* Swap Big endian to host
|
||||||
*/
|
*/
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapBigI16ToHost(gsu16 in)
|
||||||
|
{
|
||||||
|
return GSSwapI16(in);
|
||||||
|
}
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapBigI32ToHost(gsu32 in)
|
||||||
|
{
|
||||||
|
return GSSwapI32(in);
|
||||||
|
}
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapBigI64ToHost(gsu64 in)
|
||||||
|
{
|
||||||
|
return GSSwapI64(in);
|
||||||
|
}
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapBigI128ToHost(gsu128 in)
|
||||||
|
{
|
||||||
|
return GSSwapI128(in);
|
||||||
|
}
|
||||||
static inline double
|
static inline double
|
||||||
NSSwapBigDoubleToHost(NSSwappedDouble num)
|
NSSwapBigDoubleToHost(NSSwappedDouble num)
|
||||||
{
|
{
|
||||||
|
@ -600,6 +740,26 @@ NSSwapBigShortToHost(unsigned short num)
|
||||||
/*
|
/*
|
||||||
* Swap Host to Big endian
|
* Swap Host to Big endian
|
||||||
*/
|
*/
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapHostI16ToBig(gsu16 in)
|
||||||
|
{
|
||||||
|
return GSSwapI16(in);
|
||||||
|
}
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapHostI32ToBig(gsu32 in)
|
||||||
|
{
|
||||||
|
return GSSwapI32(in);
|
||||||
|
}
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapHostI64ToBig(gsu64 in)
|
||||||
|
{
|
||||||
|
return GSSwapI64(in);
|
||||||
|
}
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapHostI128ToBig(gsu128 in)
|
||||||
|
{
|
||||||
|
return GSSwapI128(in);
|
||||||
|
}
|
||||||
static inline NSSwappedDouble
|
static inline NSSwappedDouble
|
||||||
NSSwapHostDoubleToBig(double num)
|
NSSwapHostDoubleToBig(double num)
|
||||||
{
|
{
|
||||||
|
@ -639,6 +799,27 @@ NSSwapHostShortToBig(unsigned short num)
|
||||||
/*
|
/*
|
||||||
* Swap Little endian to Host
|
* Swap Little endian to Host
|
||||||
*/
|
*/
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapLittleI16ToHost(gsu16 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapLittleI32ToHost(gsu32 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapLittleI64ToHost(gsu64 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapLittleI128ToHost(gsu128 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
static inline double
|
static inline double
|
||||||
NSSwapLittleDoubleToHost(NSSwappedDouble num)
|
NSSwapLittleDoubleToHost(NSSwappedDouble num)
|
||||||
{
|
{
|
||||||
|
@ -678,6 +859,27 @@ NSSwapLittleShortToHost(unsigned short num)
|
||||||
/*
|
/*
|
||||||
* Swap Host to Little endian
|
* Swap Host to Little endian
|
||||||
*/
|
*/
|
||||||
|
static inline gsu16
|
||||||
|
GSSwapHostI16ToLittle(gsu16 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu32
|
||||||
|
GSSwapHostI32ToLittle(gsu32 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu64
|
||||||
|
GSSwapHostI64ToLittle(gsu64 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
static inline gsu128
|
||||||
|
GSSwapHostI128ToLittle(gsu128 in)
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
static inline NSSwappedDouble
|
static inline NSSwappedDouble
|
||||||
NSSwapHostDoubleToLittle(double num)
|
NSSwapHostDoubleToLittle(double num)
|
||||||
{
|
{
|
||||||
|
|
132
Source/NSData.m
132
Source/NSData.m
|
@ -640,9 +640,7 @@ failure:
|
||||||
[self deserializeBytes: &length
|
[self deserializeBytes: &length
|
||||||
length: sizeof(length)
|
length: sizeof(length)
|
||||||
atCursor: cursor];
|
atCursor: cursor];
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
length = GSSwapBigI32ToHost(length);
|
||||||
length = GSSwapI32(length);
|
|
||||||
#endif
|
|
||||||
if (length == -1)
|
if (length == -1)
|
||||||
{
|
{
|
||||||
*(const char**)data = NULL;
|
*(const char**)data = NULL;
|
||||||
|
@ -813,9 +811,7 @@ failure:
|
||||||
[self deserializeBytes: &ni
|
[self deserializeBytes: &ni
|
||||||
length: sizeof(ni)
|
length: sizeof(ni)
|
||||||
atCursor: cursor];
|
atCursor: cursor];
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapBigI16ToHost(ni);
|
||||||
ni = GSSwapI16(ni);
|
|
||||||
#endif
|
|
||||||
if (ni == 0)
|
if (ni == 0)
|
||||||
{
|
{
|
||||||
*(Class*)data = 0;
|
*(Class*)data = 0;
|
||||||
|
@ -847,15 +843,11 @@ failure:
|
||||||
[self deserializeBytes: &ln
|
[self deserializeBytes: &ln
|
||||||
length: sizeof(ln)
|
length: sizeof(ln)
|
||||||
atCursor: cursor];
|
atCursor: cursor];
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ln = GSSwapBigI16ToHost(ln);
|
||||||
ln = GSSwapI16(ln);
|
|
||||||
#endif
|
|
||||||
[self deserializeBytes: <
|
[self deserializeBytes: <
|
||||||
length: sizeof(lt)
|
length: sizeof(lt)
|
||||||
atCursor: cursor];
|
atCursor: cursor];
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
lt = GSSwapBigI16ToHost(lt);
|
||||||
lt = GSSwapI16(lt);
|
|
||||||
#endif
|
|
||||||
if (ln == 0)
|
if (ln == 0)
|
||||||
{
|
{
|
||||||
*(SEL*)data = 0;
|
*(SEL*)data = 0;
|
||||||
|
@ -1268,24 +1260,18 @@ failure:
|
||||||
|
|
||||||
case _C_CHARPTR:
|
case _C_CHARPTR:
|
||||||
{
|
{
|
||||||
unsigned len;
|
gsu32 len;
|
||||||
gss32 ni;
|
gsu32 ni;
|
||||||
|
|
||||||
if (!*(void**)data)
|
if (!*(void**)data)
|
||||||
{
|
{
|
||||||
ni = -1;
|
ni = (gsu32)-1;
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapHostI32ToBig(ni);
|
||||||
ni = GSSwapI32(ni);
|
|
||||||
#endif
|
|
||||||
[self appendBytes: (void*)&ni length: sizeof(ni)];
|
[self appendBytes: (void*)&ni length: sizeof(ni)];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
len = strlen(*(void**)data);
|
len = (gsu32)strlen(*(void**)data);
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapHostI32ToBig(len);
|
||||||
ni = GSSwapI32(len);
|
|
||||||
#else
|
|
||||||
ni = len;
|
|
||||||
#endif
|
|
||||||
[self appendBytes: (void*)&ni length: sizeof(ni)];
|
[self appendBytes: (void*)&ni length: sizeof(ni)];
|
||||||
[self appendBytes: *(void**)data length: len];
|
[self appendBytes: *(void**)data length: len];
|
||||||
return;
|
return;
|
||||||
|
@ -1396,11 +1382,7 @@ failure:
|
||||||
gsu16 ln = (gsu16)strlen(name);
|
gsu16 ln = (gsu16)strlen(name);
|
||||||
gsu16 ni;
|
gsu16 ni;
|
||||||
|
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapHostI16ToBig(ln);
|
||||||
ni = GSSwapI16(ln);
|
|
||||||
#else
|
|
||||||
ni = ln;
|
|
||||||
#endif
|
|
||||||
[self appendBytes: &ni length: sizeof(ni)];
|
[self appendBytes: &ni length: sizeof(ni)];
|
||||||
if (ln)
|
if (ln)
|
||||||
{
|
{
|
||||||
|
@ -1416,17 +1398,9 @@ failure:
|
||||||
gsu16 lt = (gsu16)strlen(types);
|
gsu16 lt = (gsu16)strlen(types);
|
||||||
gsu16 ni;
|
gsu16 ni;
|
||||||
|
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapHostI16ToBig(ln);
|
||||||
ni = GSSwapI16(ln);
|
|
||||||
#else
|
|
||||||
ni = ln;
|
|
||||||
#endif
|
|
||||||
[self appendBytes: &ni length: sizeof(ni)];
|
[self appendBytes: &ni length: sizeof(ni)];
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapHostI16ToBig(lt);
|
||||||
ni = GSSwapI16(lt);
|
|
||||||
#else
|
|
||||||
ni = lt;
|
|
||||||
#endif
|
|
||||||
[self appendBytes: &ni length: sizeof(ni)];
|
[self appendBytes: &ni length: sizeof(ni)];
|
||||||
if (ln)
|
if (ln)
|
||||||
{
|
{
|
||||||
|
@ -1444,13 +1418,13 @@ failure:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)serializeInt: (int)value
|
- (void) serializeInt: (int)value
|
||||||
{
|
{
|
||||||
unsigned ni = NSSwapHostIntToBig(value);
|
unsigned ni = NSSwapHostIntToBig(value);
|
||||||
[self appendBytes: &ni length: sizeof(unsigned)];
|
[self appendBytes: &ni length: sizeof(unsigned)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)serializeInt: (int)value atIndex: (unsigned)index
|
- (void) serializeInt: (int)value atIndex: (unsigned)index
|
||||||
{
|
{
|
||||||
unsigned ni = NSSwapHostIntToBig(value);
|
unsigned ni = NSSwapHostIntToBig(value);
|
||||||
NSRange range = { index, sizeof(int) };
|
NSRange range = { index, sizeof(int) };
|
||||||
|
@ -1705,10 +1679,10 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
*pos += len;
|
*pos += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)deserializeDataAt: (void*)data
|
- (void) deserializeDataAt: (void*)data
|
||||||
ofObjCType: (const char*)type
|
ofObjCType: (const char*)type
|
||||||
atCursor: (unsigned*)cursor
|
atCursor: (unsigned*)cursor
|
||||||
context: (id <NSObjCTypeSerializationCallBack>)callback
|
context: (id <NSObjCTypeSerializationCallBack>)callback
|
||||||
{
|
{
|
||||||
if (data == 0 || type == 0)
|
if (data == 0 || type == 0)
|
||||||
{
|
{
|
||||||
|
@ -1740,9 +1714,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
[self deserializeBytes: &len
|
[self deserializeBytes: &len
|
||||||
length: sizeof(len)
|
length: sizeof(len)
|
||||||
atCursor: cursor];
|
atCursor: cursor];
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
len = GSSwapBigI32ToHost(len);
|
||||||
len = GSSwapI32(len);
|
|
||||||
#endif
|
|
||||||
if (len == -1)
|
if (len == -1)
|
||||||
{
|
{
|
||||||
*(const char**)data = NULL;
|
*(const char**)data = NULL;
|
||||||
|
@ -1893,9 +1865,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
gsu16 ni;
|
gsu16 ni;
|
||||||
|
|
||||||
getBytes((void*)&ni, bytes, sizeof(ni), length, cursor);
|
getBytes((void*)&ni, bytes, sizeof(ni), length, cursor);
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapBigI16ToHost(ni);
|
||||||
ni = GSSwapI16(ni);
|
|
||||||
#endif
|
|
||||||
if (ni == 0)
|
if (ni == 0)
|
||||||
{
|
{
|
||||||
*(Class*)data = 0;
|
*(Class*)data = 0;
|
||||||
|
@ -1923,13 +1893,9 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
gsu16 lt;
|
gsu16 lt;
|
||||||
|
|
||||||
getBytes((void*)&ln, bytes, sizeof(ln), length, cursor);
|
getBytes((void*)&ln, bytes, sizeof(ln), length, cursor);
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ln = GSSwapBigI16ToHost(ln);
|
||||||
ln = GSSwapI16(ln);
|
|
||||||
#endif
|
|
||||||
getBytes((void*)<, bytes, sizeof(lt), length, cursor);
|
getBytes((void*)<, bytes, sizeof(lt), length, cursor);
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
lt = GSSwapBigI16ToHost(lt);
|
||||||
lt = GSSwapI16(lt);
|
|
||||||
#endif
|
|
||||||
if (ln == 0)
|
if (ln == 0)
|
||||||
{
|
{
|
||||||
*(SEL*)data = 0;
|
*(SEL*)data = 0;
|
||||||
|
@ -2010,11 +1976,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
}
|
}
|
||||||
x = *(gsu16*)(bytes + *cursor);
|
x = *(gsu16*)(bytes + *cursor);
|
||||||
*cursor += 2;
|
*cursor += 2;
|
||||||
#if GS_WORDS_BIGENDIAN
|
*ref = (unsigned int)GSSwapBigI16ToHost(x);
|
||||||
*ref = (unsigned int)x;
|
|
||||||
#else
|
|
||||||
*ref = (unsigned int)GSSwapI16(x);
|
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -2029,11 +1991,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
}
|
}
|
||||||
x = *(gsu32*)(bytes + *cursor);
|
x = *(gsu32*)(bytes + *cursor);
|
||||||
*cursor += 4;
|
*cursor += 4;
|
||||||
#if GS_WORDS_BIGENDIAN
|
*ref = (unsigned int)GSSwapBigI32ToHost(x);
|
||||||
*ref = (unsigned int)x;
|
|
||||||
#else
|
|
||||||
*ref = (unsigned int)GSSwapI32(x);
|
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2662,18 +2620,12 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
if (!*(void**)data)
|
if (!*(void**)data)
|
||||||
{
|
{
|
||||||
ni = -1;
|
ni = -1;
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapHostI32ToBig(ni);
|
||||||
ni = GSSwapI32(ni);
|
|
||||||
#endif
|
|
||||||
[self appendBytes: (void*)&len length: sizeof(len)];
|
[self appendBytes: (void*)&len length: sizeof(len)];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
len = strlen(*(void**)data);
|
len = strlen(*(void**)data);
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapHostI32ToBig(len);
|
||||||
ni = GSSwapI32(len);
|
|
||||||
#else
|
|
||||||
ni = len;
|
|
||||||
#endif
|
|
||||||
minimum = length + len + sizeof(ni);
|
minimum = length + len + sizeof(ni);
|
||||||
if (minimum > capacity)
|
if (minimum > capacity)
|
||||||
{
|
{
|
||||||
|
@ -2812,11 +2764,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
{
|
{
|
||||||
[self _grow: minimum];
|
[self _grow: minimum];
|
||||||
}
|
}
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapHostI16ToBig(ln);
|
||||||
ni = GSSwapI16(ln);
|
|
||||||
#else
|
|
||||||
ni = ln;
|
|
||||||
#endif
|
|
||||||
memcpy(bytes+length, &ni, sizeof(ni));
|
memcpy(bytes+length, &ni, sizeof(ni));
|
||||||
length += sizeof(ni);
|
length += sizeof(ni);
|
||||||
if (ln)
|
if (ln)
|
||||||
|
@ -2839,18 +2787,10 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
{
|
{
|
||||||
[self _grow: minimum];
|
[self _grow: minimum];
|
||||||
}
|
}
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapHostI16ToBig(ln);
|
||||||
ni = GSSwapI16(ln);
|
|
||||||
#else
|
|
||||||
ni = ln;
|
|
||||||
#endif
|
|
||||||
memcpy(bytes+length, &ni, sizeof(ni));
|
memcpy(bytes+length, &ni, sizeof(ni));
|
||||||
length += sizeof(ni);
|
length += sizeof(ni);
|
||||||
#ifndef GS_WORDS_BIGENDIAN
|
ni = GSSwapHostI16ToBig(lt);
|
||||||
ni = GSSwapI16(lt);
|
|
||||||
#else
|
|
||||||
ni = lt;
|
|
||||||
#endif
|
|
||||||
memcpy(bytes+length, &ni, sizeof(ni));
|
memcpy(bytes+length, &ni, sizeof(ni));
|
||||||
length += sizeof(ni);
|
length += sizeof(ni);
|
||||||
if (ln)
|
if (ln)
|
||||||
|
@ -2903,11 +2843,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
[self _grow: length + 3];
|
[self _grow: length + 3];
|
||||||
}
|
}
|
||||||
*(gsu8*)(bytes + length++) = tag;
|
*(gsu8*)(bytes + length++) = tag;
|
||||||
#if GS_WORDS_BIGENDIAN
|
*(gsu16*)(bytes + length) = GSSwapHostI16ToBig(x);
|
||||||
*(gsu16*)(bytes + length) = (gsu16)x;
|
|
||||||
#else
|
|
||||||
*(gsu16*)(bytes + length) = GSSwapI16(x);
|
|
||||||
#endif
|
|
||||||
length += 2;
|
length += 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2920,11 +2856,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
||||||
[self _grow: length + 5];
|
[self _grow: length + 5];
|
||||||
}
|
}
|
||||||
*(gsu8*)(bytes + length++) = tag;
|
*(gsu8*)(bytes + length++) = tag;
|
||||||
#if GS_WORDS_BIGENDIAN
|
*(gsu32*)(bytes + length) = GSSwapHostI32ToBig(x);
|
||||||
*(gsu32*)(bytes + length) = (gsu32)x;
|
|
||||||
#else
|
|
||||||
*(gsu32*)(bytes + length) = GSSwapI32(x);
|
|
||||||
#endif
|
|
||||||
length += 4;
|
length += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -884,10 +884,7 @@ mapClassName(NSUnarchiverObjectInfo *info)
|
||||||
#if GS_HAVE_I64
|
#if GS_HAVE_I64
|
||||||
bigval = val;
|
bigval = val;
|
||||||
#else
|
#else
|
||||||
#if GS_WORDS_BIGENDIAN == 0
|
val = GSSwapBigI64ToHost(val);
|
||||||
val = GSSwapI64(val);
|
|
||||||
#endif
|
|
||||||
bigval = *(gsu32*)&val;
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -900,9 +897,7 @@ mapClassName(NSUnarchiverObjectInfo *info)
|
||||||
#if GS_HAVE_I128
|
#if GS_HAVE_I128
|
||||||
bigval = val;
|
bigval = val;
|
||||||
#else
|
#else
|
||||||
#if GS_WORDS_BIGENDIAN == 0
|
val = GSSwapBigI128ToHost(val);
|
||||||
val = GSSwapI128(val);
|
|
||||||
#endif
|
|
||||||
#if GS_HAVE_I64
|
#if GS_HAVE_I64
|
||||||
bigval = *(gsu64*)&val;
|
bigval = *(gsu64*)&val;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <Foundation/NSNotification.h>
|
#include <Foundation/NSNotification.h>
|
||||||
#include <Foundation/NSNotificationQueue.h>
|
#include <Foundation/NSNotificationQueue.h>
|
||||||
#include <Foundation/NSHost.h>
|
#include <Foundation/NSHost.h>
|
||||||
|
#include <Foundation/NSByteOrder.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <Windows32/Sockets.h>
|
#include <Windows32/Sockets.h>
|
||||||
|
@ -116,7 +117,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sin->sin_addr.s_addr = htonl(INADDR_ANY);
|
sin->sin_addr.s_addr = GSSwapHostI32ToBig(INADDR_ANY);
|
||||||
|
|
||||||
if (svc == nil)
|
if (svc == nil)
|
||||||
{
|
{
|
||||||
|
@ -133,9 +134,9 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
|
|
||||||
if (*ptr == '\0' && val <= 0xffff)
|
if (*ptr == '\0' && val <= 0xffff)
|
||||||
{
|
{
|
||||||
short v = val;
|
gsu16 v = val;
|
||||||
|
|
||||||
sin->sin_port = htons(v);
|
sin->sin_port = GSSwapHostI16ToBig(v);
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -237,7 +238,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
if (connect(net, (struct sockaddr*)&sin, sizeof(sin)) < 0)
|
if (connect(net, (struct sockaddr*)&sin, sizeof(sin)) < 0)
|
||||||
{
|
{
|
||||||
NSLog(@"unable to make connection to %s:%d - %s",
|
NSLog(@"unable to make connection to %s:%d - %s",
|
||||||
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), strerror(errno));
|
inet_ntoa(sin.sin_addr),
|
||||||
|
GSSwapBigI16ToHost(sin.sin_port), strerror(errno));
|
||||||
[self release];
|
[self release];
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -290,7 +292,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
if (errno != EINPROGRESS)
|
if (errno != EINPROGRESS)
|
||||||
{
|
{
|
||||||
NSLog(@"unable to make connection to %s:%d - %s",
|
NSLog(@"unable to make connection to %s:%d - %s",
|
||||||
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), strerror(errno));
|
inet_ntoa(sin.sin_addr),
|
||||||
|
GSSwapBigI16ToHost(sin.sin_port), strerror(errno));
|
||||||
[self release];
|
[self release];
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -339,7 +342,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
if (bind(net, (struct sockaddr *)&sin, sizeof(sin)) < 0)
|
if (bind(net, (struct sockaddr *)&sin, sizeof(sin)) < 0)
|
||||||
{
|
{
|
||||||
NSLog(@"unable to bind to port %s:%d - %s",
|
NSLog(@"unable to bind to port %s:%d - %s",
|
||||||
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), strerror(errno));
|
inet_ntoa(sin.sin_addr),
|
||||||
|
GSSwapBigI16ToHost(sin.sin_port), strerror(errno));
|
||||||
(void) close(net);
|
(void) close(net);
|
||||||
[self release];
|
[self release];
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -1330,7 +1334,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
{
|
{
|
||||||
address = [NSString stringWithCString: (char*)inet_ntoa(sin->sin_addr)];
|
address = [NSString stringWithCString: (char*)inet_ntoa(sin->sin_addr)];
|
||||||
[address retain];
|
[address retain];
|
||||||
service = [NSString stringWithFormat: @"%d", (int)ntohs(sin->sin_port)];
|
service = [NSString stringWithFormat: @"%d",
|
||||||
|
(int)GSSwapBigI16ToHost(sin->sin_port)];
|
||||||
[service retain];
|
[service retain];
|
||||||
protocol = @"tcp";
|
protocol = @"tcp";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue