2003-08-12 12:42:52 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: Client/Server Common Code
|
|
|
|
* MODULE: memory_routines.h
|
|
|
|
* DESCRIPTION: Misc memory content routines
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Interbase Public
|
|
|
|
* License Version 1.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy
|
|
|
|
* of the License at http://www.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* Created by: Dimitry Sibiryakov <aafemt@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MEMORY_ROUTINES_H
|
|
|
|
#define MEMORY_ROUTINES_H
|
|
|
|
|
|
|
|
|
2006-01-26 11:45:02 +01:00
|
|
|
inline USHORT get_short(const UCHAR* p)
|
2003-08-12 12:42:52 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* g e t _ s h o r t
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2006-01-26 11:45:02 +01:00
|
|
|
* Gather one unsigned short int
|
|
|
|
* from two chars
|
2003-08-12 12:42:52 +02:00
|
|
|
*
|
|
|
|
**************************************/
|
2006-01-26 11:45:02 +01:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
|
|
|
// little-endian
|
|
|
|
USHORT temp;
|
|
|
|
memcpy(&temp, p, sizeof(USHORT));
|
|
|
|
return temp;
|
2003-08-12 12:42:52 +02:00
|
|
|
#else
|
2006-01-26 11:45:02 +01:00
|
|
|
// big-endian
|
|
|
|
union {
|
|
|
|
USHORT n;
|
|
|
|
UCHAR c[2];
|
|
|
|
} temp;
|
2003-08-12 12:42:52 +02:00
|
|
|
|
2006-01-26 11:45:02 +01:00
|
|
|
temp.c[0] = p[0];
|
|
|
|
temp.c[1] = p[1];
|
2003-08-12 12:42:52 +02:00
|
|
|
|
2006-01-26 11:45:02 +01:00
|
|
|
return temp.n;
|
|
|
|
#endif
|
2003-08-12 12:42:52 +02:00
|
|
|
}
|
|
|
|
|
2003-08-18 12:31:56 +02:00
|
|
|
inline SLONG get_long(const UCHAR* p)
|
2003-08-12 12:42:52 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
2006-01-26 11:45:02 +01:00
|
|
|
* g e t _ l o n g
|
2003-08-12 12:42:52 +02:00
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2006-01-26 11:45:02 +01:00
|
|
|
* Gather one signed long int
|
|
|
|
* from four chars
|
2003-08-12 12:42:52 +02:00
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
#ifndef WORDS_BIGENDIAN
|
2006-01-26 11:45:02 +01:00
|
|
|
// little-endian
|
|
|
|
SLONG temp;
|
|
|
|
memcpy(&temp, p, sizeof(SLONG));
|
|
|
|
return temp;
|
2003-08-12 12:42:52 +02:00
|
|
|
#else
|
2006-01-26 11:45:02 +01:00
|
|
|
// big-endian
|
|
|
|
union {
|
|
|
|
SLONG n;
|
|
|
|
UCHAR c[4];
|
|
|
|
} temp;
|
|
|
|
|
|
|
|
temp.c[0] = p[0];
|
|
|
|
temp.c[1] = p[1];
|
|
|
|
temp.c[2] = p[2];
|
|
|
|
temp.c[3] = p[3];
|
|
|
|
|
|
|
|
return temp.n;
|
2003-08-12 12:42:52 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-01-26 11:45:02 +01:00
|
|
|
inline void put_short(UCHAR* p, USHORT value)
|
2003-08-12 12:42:52 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
2006-01-26 11:45:02 +01:00
|
|
|
* p u t _ s h o r t
|
2003-08-12 12:42:52 +02:00
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2006-01-26 11:45:02 +01:00
|
|
|
* Store one unsigned short int as
|
|
|
|
* two chars
|
2003-08-12 12:42:52 +02:00
|
|
|
*
|
|
|
|
**************************************/
|
2006-01-26 11:45:02 +01:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
|
|
|
// little-endian
|
|
|
|
memcpy(p, &value, sizeof(USHORT));
|
2003-08-12 12:42:52 +02:00
|
|
|
#else
|
2006-01-26 11:45:02 +01:00
|
|
|
// big-endian
|
|
|
|
union {
|
|
|
|
USHORT n;
|
|
|
|
UCHAR c[2];
|
|
|
|
} temp;
|
2003-08-12 12:42:52 +02:00
|
|
|
|
2006-01-26 11:45:02 +01:00
|
|
|
temp.n = value;
|
2003-08-12 12:42:52 +02:00
|
|
|
|
2006-01-26 11:45:02 +01:00
|
|
|
p[0] = temp.c[0];
|
|
|
|
p[1] = temp.c[1];
|
|
|
|
#endif
|
2003-08-12 12:42:52 +02:00
|
|
|
}
|
|
|
|
|
2006-01-26 11:45:02 +01:00
|
|
|
inline void put_long(UCHAR* p, SLONG value)
|
2003-08-12 12:42:52 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
2006-01-26 11:45:02 +01:00
|
|
|
* p u t _ l o n g
|
2003-08-12 12:42:52 +02:00
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
2006-01-26 11:45:02 +01:00
|
|
|
* Store one signed long int as
|
|
|
|
* four chars
|
2003-08-12 12:42:52 +02:00
|
|
|
*
|
|
|
|
**************************************/
|
2006-01-26 11:45:02 +01:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
|
|
|
// little-endian
|
|
|
|
memcpy(p, &value, sizeof(SLONG));
|
2003-08-12 12:42:52 +02:00
|
|
|
#else
|
2006-01-26 11:45:02 +01:00
|
|
|
// big-endian
|
|
|
|
union {
|
|
|
|
SLONG n;
|
|
|
|
UCHAR c[4];
|
|
|
|
} temp;
|
|
|
|
|
|
|
|
temp.n = value;
|
|
|
|
|
|
|
|
p[0] = temp.c[0];
|
|
|
|
p[1] = temp.c[1];
|
|
|
|
p[2] = temp.c[2];
|
|
|
|
p[3] = temp.c[3];
|
|
|
|
#endif
|
2003-08-12 12:42:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MEMORY_ROUTINES_H
|