postgresql/src/include/c.h

807 lines
19 KiB
C
Raw Normal View History

1996-10-31 08:10:14 +01:00
/*-------------------------------------------------------------------------
*
* c.h
* Fundamental C definitions. This is included by every .c file in
* postgres.
1996-10-31 08:10:14 +01:00
*
*
* Copyright (c) 1994, Regents of the University of California
*
1999-07-01 21:47:25 +02:00
* $Id: c.h,v 1.58 1999/07/01 19:47:25 momjian Exp $
1996-10-31 08:10:14 +01:00
*
*-------------------------------------------------------------------------
*/
/*
* TABLE OF CONTENTS
1996-10-31 08:10:14 +01:00
*
* When adding stuff to this file, please try and put stuff
* into the relevant section, or add new sections as appropriate.
1996-10-31 08:10:14 +01:00
*
* section description
* ------- ------------------------------------------------
* 1) bool, true, false, TRUE, FALSE, NULL
* 2) non-ansi C definitions:
* type prefixes: const, signed, volatile, inline
* cpp magic macros
* 3) standard system types
* 4) datum type
* 5) IsValid macros for system types
* 6) offsetof, lengthof, endof
* 7) exception handling definitions, Assert, Trap, etc macros
* 8) Min, Max, Abs, StrNCpy macros
* 9) externs
* 10) Berkeley-specific defs
* 11) system-specific hacks
1996-10-31 08:10:14 +01:00
*
* NOTES
1996-10-31 08:10:14 +01:00
*
* This file is MACHINE AND COMPILER dependent!!! (For now.)
1996-10-31 08:10:14 +01:00
*
* ----------------------------------------------------------------
*/
#ifndef C_H
1996-10-31 08:10:14 +01:00
#define C_H
/* We have to include stdlib.h here because it defines many of these macros
on some platforms, and we only want our definitions used if stdlib.h doesn't
have its own. The same goes for stddef and stdarg if present.
*/
#include <stdlib.h>
#ifdef STDC_HEADERS
#include <stddef.h>
#include <stdarg.h>
#endif
1999-01-17 07:20:06 +01:00
#ifdef __CYGWIN32__
#include <errno.h>
#endif
1996-10-31 08:10:14 +01:00
/* ----------------------------------------------------------------
* Section 1: bool, true, false, TRUE, FALSE, NULL
1996-10-31 08:10:14 +01:00
* ----------------------------------------------------------------
*/
/*
1999-05-25 18:15:34 +02:00
* bool
* Boolean value, either true or false.
1996-10-31 08:10:14 +01:00
*
*/
#ifndef __cplusplus
1998-10-04 17:38:58 +02:00
#ifndef bool
typedef char bool;
1999-05-25 18:15:34 +02:00
#endif /* ndef bool */
#endif /* not C++ */
1999-07-01 21:47:25 +02:00
#ifndef true
#define true ((bool) 1)
1999-07-01 21:47:25 +02:00
#endif
#ifndef false
#define false ((bool) 0)
#endif
typedef bool *BoolPtr;
1996-10-31 08:10:14 +01:00
#ifndef TRUE
#define TRUE 1
#endif /* TRUE */
1996-10-31 08:10:14 +01:00
#ifndef FALSE
#define FALSE 0
#endif /* FALSE */
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* NULL
* Null pointer.
1996-10-31 08:10:14 +01:00
*/
#ifndef NULL
#define NULL ((void *) 0)
#endif /* !defined(NULL) */
1996-10-31 08:10:14 +01:00
/* ----------------------------------------------------------------
* Section 2: non-ansi C definitions:
1996-10-31 08:10:14 +01:00
*
* type prefixes: const, signed, volatile, inline
* cpp magic macros
* ----------------------------------------------------------------
1996-10-31 08:10:14 +01:00
*/
/*
* We used to define const, signed, volatile, and inline as empty
* if __STDC__ wasn't defined. Now we let configure test whether
* those keywords work; config.h defines them as empty if not.
1996-10-31 08:10:14 +01:00
*/
/*
1999-05-25 18:15:34 +02:00
* CppAsString
* Convert the argument to a string, using the C preprocessor.
1999-05-25 18:15:34 +02:00
* CppConcat
* Concatenate two arguments together, using the C preprocessor.
*
* Note: the standard Autoconf macro AC_C_STRINGIZE actually only checks
* whether #identifier works, but if we have that we likely have ## too.
1996-10-31 08:10:14 +01:00
*/
#if defined(HAVE_STRINGIZE)
1996-10-31 08:10:14 +01:00
#define CppAsString(identifier) #identifier
#define CppConcat(x, y) x##y
1996-10-31 08:10:14 +01:00
#else /* !HAVE_STRINGIZE */
1996-10-31 08:10:14 +01:00
#define CppAsString(identifier) "identifier"
1996-10-31 08:10:14 +01:00
/*
* CppIdentity -- On Reiser based cpp's this is used to concatenate
* two tokens. That is
* CppIdentity(A)B ==> AB
* We renamed it to _private_CppIdentity because it should not
* be referenced outside this file. On other cpp's it
* produces A B.
1996-10-31 08:10:14 +01:00
*/
#define _priv_CppIdentity(x)x
#define CppConcat(x, y) _priv_CppIdentity(x)y
1996-10-31 08:10:14 +01:00
#endif /* !HAVE_STRINGIZE */
/*
* dummyret is used to set return values in macros that use ?: to make
* assignments. gcc wants these to be void, other compilers like char
*/
1999-05-25 18:15:34 +02:00
#ifdef __GNUC__ /* GNU cc */
#define dummyret void
#else
#define dummyret char
1996-10-31 08:10:14 +01:00
#endif
/* ----------------------------------------------------------------
* Section 3: standard system types
1996-10-31 08:10:14 +01:00
* ----------------------------------------------------------------
*/
/*
1999-05-25 18:15:34 +02:00
* Pointer
* Variable holding address of any memory resident object.
*
* XXX Pointer arithmetic is done with this, so it can't be void *
* under "true" ANSI compilers.
*/
typedef char *Pointer;
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* intN
* Signed integer, EXACTLY N BITS IN SIZE,
* used for numerical computations and the
* frontend/backend protocol.
1996-10-31 08:10:14 +01:00
*/
typedef signed char int8; /* == 8 bits */
typedef signed short int16; /* == 16 bits */
typedef signed int int32; /* == 32 bits */
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* uintN
* Unsigned integer, EXACTLY N BITS IN SIZE,
* used for numerical computations and the
* frontend/backend protocol.
1996-10-31 08:10:14 +01:00
*/
typedef unsigned char uint8; /* == 8 bits */
typedef unsigned short uint16; /* == 16 bits */
typedef unsigned int uint32; /* == 32 bits */
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* floatN
* Floating point number, AT LEAST N BITS IN SIZE,
* used for numerical computations.
1996-10-31 08:10:14 +01:00
*
* Since sizeof(floatN) may be > sizeof(char *), always pass
* floatN by reference.
1996-10-31 08:10:14 +01:00
*/
typedef float float32data;
typedef double float64data;
typedef float *float32;
typedef double *float64;
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* boolN
* Boolean value, AT LEAST N BITS IN SIZE.
1996-10-31 08:10:14 +01:00
*/
typedef uint8 bool8; /* >= 8 bits */
typedef uint16 bool16; /* >= 16 bits */
typedef uint32 bool32; /* >= 32 bits */
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* bitsN
* Unit of bitwise operation, AT LEAST N BITS IN SIZE.
1996-10-31 08:10:14 +01:00
*/
typedef uint8 bits8; /* >= 8 bits */
typedef uint16 bits16; /* >= 16 bits */
typedef uint32 bits32; /* >= 32 bits */
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* wordN
* Unit of storage, AT LEAST N BITS IN SIZE,
* used to fetch/store data.
1996-10-31 08:10:14 +01:00
*/
typedef uint8 word8; /* >= 8 bits */
typedef uint16 word16; /* >= 16 bits */
typedef uint32 word32; /* >= 32 bits */
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* Size
* Size of any memory resident object, as returned by sizeof.
1996-10-31 08:10:14 +01:00
*/
typedef size_t Size;
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* Index
* Index into any memory resident array.
1996-10-31 08:10:14 +01:00
*
* Note:
* Indices are non negative.
1996-10-31 08:10:14 +01:00
*/
typedef unsigned int Index;
1996-10-31 08:10:14 +01:00
#define MAXDIM 6
typedef struct
{
int indx[MAXDIM];
} IntArray;
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* Offset
* Offset into any memory resident array.
1996-10-31 08:10:14 +01:00
*
* Note:
* This differs from an Index in that an Index is always
* non negative, whereas Offset may be negative.
1996-10-31 08:10:14 +01:00
*/
typedef signed int Offset;
1996-10-31 08:10:14 +01:00
/* ----------------------------------------------------------------
* Section 4: datum type + support macros
1996-10-31 08:10:14 +01:00
* ----------------------------------------------------------------
*/
/*
1999-05-25 18:15:34 +02:00
* datum.h
* POSTGRES abstract data type datum representation definitions.
1996-10-31 08:10:14 +01:00
*
* Note:
*
* Port Notes:
* Postgres makes the following assumption about machines:
1996-10-31 08:10:14 +01:00
*
* sizeof(Datum) == sizeof(long) >= sizeof(void *) >= 4
1996-10-31 08:10:14 +01:00
*
* Postgres also assumes that
1996-10-31 08:10:14 +01:00
*
* sizeof(char) == 1
1996-10-31 08:10:14 +01:00
*
* and that
1996-10-31 08:10:14 +01:00
*
* sizeof(short) == 2
1996-10-31 08:10:14 +01:00
*
* If your machine meets these requirements, Datums should also be checked
* to see if the positioning is correct.
1996-10-31 08:10:14 +01:00
*
* This file is MACHINE AND COMPILER dependent!!!
1996-10-31 08:10:14 +01:00
*/
typedef unsigned long Datum; /* XXX sizeof(long) >= sizeof(void *) */
typedef Datum *DatumPtr;
1996-10-31 08:10:14 +01:00
#define GET_1_BYTE(datum) (((Datum) (datum)) & 0x000000ff)
#define GET_2_BYTES(datum) (((Datum) (datum)) & 0x0000ffff)
#define GET_4_BYTES(datum) (((Datum) (datum)) & 0xffffffff)
#define SET_1_BYTE(value) (((Datum) (value)) & 0x000000ff)
#define SET_2_BYTES(value) (((Datum) (value)) & 0x0000ffff)
#define SET_4_BYTES(value) (((Datum) (value)) & 0xffffffff)
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* DatumGetChar
* Returns character value of a datum.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetChar(X) ((char) GET_1_BYTE(X))
/*
1999-05-25 18:15:34 +02:00
* CharGetDatum
* Returns datum representation for a character.
1996-10-31 08:10:14 +01:00
*/
#define CharGetDatum(X) ((Datum) SET_1_BYTE(X))
/*
1999-05-25 18:15:34 +02:00
* Int8GetDatum
* Returns datum representation for an 8-bit integer.
1996-10-31 08:10:14 +01:00
*/
#define Int8GetDatum(X) ((Datum) SET_1_BYTE(X))
/*
1999-05-25 18:15:34 +02:00
* DatumGetUInt8
* Returns 8-bit unsigned integer value of a datum.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetUInt8(X) ((uint8) GET_1_BYTE(X))
/*
1999-05-25 18:15:34 +02:00
* UInt8GetDatum
* Returns datum representation for an 8-bit unsigned integer.
1996-10-31 08:10:14 +01:00
*/
#define UInt8GetDatum(X) ((Datum) SET_1_BYTE(X))
/*
1999-05-25 18:15:34 +02:00
* DatumGetInt16
* Returns 16-bit integer value of a datum.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetInt16(X) ((int16) GET_2_BYTES(X))
/*
1999-05-25 18:15:34 +02:00
* Int16GetDatum
* Returns datum representation for a 16-bit integer.
1996-10-31 08:10:14 +01:00
*/
#define Int16GetDatum(X) ((Datum) SET_2_BYTES(X))
/*
1999-05-25 18:15:34 +02:00
* DatumGetUInt16
* Returns 16-bit unsigned integer value of a datum.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetUInt16(X) ((uint16) GET_2_BYTES(X))
/*
1999-05-25 18:15:34 +02:00
* UInt16GetDatum
* Returns datum representation for a 16-bit unsigned integer.
1996-10-31 08:10:14 +01:00
*/
#define UInt16GetDatum(X) ((Datum) SET_2_BYTES(X))
/*
1999-05-25 18:15:34 +02:00
* DatumGetInt32
* Returns 32-bit integer value of a datum.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetInt32(X) ((int32) GET_4_BYTES(X))
/*
1999-05-25 18:15:34 +02:00
* Int32GetDatum
* Returns datum representation for a 32-bit integer.
1996-10-31 08:10:14 +01:00
*/
#define Int32GetDatum(X) ((Datum) SET_4_BYTES(X))
/*
1999-05-25 18:15:34 +02:00
* DatumGetUInt32
* Returns 32-bit unsigned integer value of a datum.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetUInt32(X) ((uint32) GET_4_BYTES(X))
/*
1999-05-25 18:15:34 +02:00
* UInt32GetDatum
* Returns datum representation for a 32-bit unsigned integer.
1996-10-31 08:10:14 +01:00
*/
#define UInt32GetDatum(X) ((Datum) SET_4_BYTES(X))
/*
1999-05-25 18:15:34 +02:00
* DatumGetObjectId
* Returns object identifier value of a datum.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetObjectId(X) ((Oid) GET_4_BYTES(X))
/*
1999-05-25 18:15:34 +02:00
* ObjectIdGetDatum
* Returns datum representation for an object identifier.
1996-10-31 08:10:14 +01:00
*/
#define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
/*
1999-05-25 18:15:34 +02:00
* DatumGetPointer
* Returns pointer value of a datum.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetPointer(X) ((Pointer) X)
/*
1999-05-25 18:15:34 +02:00
* PointerGetDatum
* Returns datum representation for a pointer.
1996-10-31 08:10:14 +01:00
*/
#define PointerGetDatum(X) ((Datum) X)
/*
1999-05-25 18:15:34 +02:00
* DatumGetName
* Returns name value of a datum.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetName(X) ((Name) DatumGetPointer((Datum) X))
/*
1999-05-25 18:15:34 +02:00
* NameGetDatum
* Returns datum representation for a name.
1996-10-31 08:10:14 +01:00
*/
#define NameGetDatum(X) PointerGetDatum((Pointer) X)
/*
1999-05-25 18:15:34 +02:00
* DatumGetFloat32
* Returns 32-bit floating point value of a datum.
* This is really a pointer, of course.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetFloat32(X) ((float32) DatumGetPointer((Datum) X))
/*
1999-05-25 18:15:34 +02:00
* Float32GetDatum
* Returns datum representation for a 32-bit floating point number.
* This is really a pointer, of course.
1996-10-31 08:10:14 +01:00
*/
#define Float32GetDatum(X) PointerGetDatum((Pointer) X)
/*
1999-05-25 18:15:34 +02:00
* DatumGetFloat64
* Returns 64-bit floating point value of a datum.
* This is really a pointer, of course.
1996-10-31 08:10:14 +01:00
*/
#define DatumGetFloat64(X) ((float64) DatumGetPointer(X))
/*
1999-05-25 18:15:34 +02:00
* Float64GetDatum
* Returns datum representation for a 64-bit floating point number.
* This is really a pointer, of course.
1996-10-31 08:10:14 +01:00
*/
#define Float64GetDatum(X) PointerGetDatum((Pointer) X)
/* ----------------------------------------------------------------
* Section 5: IsValid macros for system types
1996-10-31 08:10:14 +01:00
* ----------------------------------------------------------------
*/
/*
1999-05-25 18:15:34 +02:00
* BoolIsValid
* True iff bool is valid.
1996-10-31 08:10:14 +01:00
*/
#define BoolIsValid(boolean) ((boolean) == false || (boolean) == true)
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* PointerIsValid
* True iff pointer is valid.
1996-10-31 08:10:14 +01:00
*/
#define PointerIsValid(pointer) (bool)((void*)(pointer) != NULL)
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* PointerIsInBounds
* True iff pointer is within given bounds.
1996-10-31 08:10:14 +01:00
*
* Note:
* Assumes the bounded interval to be [min,max),
* i.e. closed on the left and open on the right.
1996-10-31 08:10:14 +01:00
*/
#define PointerIsInBounds(pointer, min, max) \
((min) <= (pointer) && (pointer) < (max))
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* PointerIsAligned
* True iff pointer is properly aligned to point to the given type.
1996-10-31 08:10:14 +01:00
*/
#define PointerIsAligned(pointer, type) \
(((long)(pointer) % (sizeof (type))) == 0)
1996-10-31 08:10:14 +01:00
/* ----------------------------------------------------------------
* Section 6: offsetof, lengthof, endof
1996-10-31 08:10:14 +01:00
* ----------------------------------------------------------------
*/
/*
1999-05-25 18:15:34 +02:00
* offsetof
* Offset of a structure/union field within that structure/union.
1996-10-31 08:10:14 +01:00
*
* XXX This is supposed to be part of stddef.h, but isn't on
* some systems (like SunOS 4).
1996-10-31 08:10:14 +01:00
*/
#ifndef offsetof
#define offsetof(type, field) ((long) &((type *)0)->field)
#endif /* offsetof */
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* lengthof
* Number of elements in an array.
1996-10-31 08:10:14 +01:00
*/
#define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* endof
* Address of the element one past the last in an array.
1996-10-31 08:10:14 +01:00
*/
#define endof(array) (&array[lengthof(array)])
/* ----------------------------------------------------------------
* Section 7: exception handling definitions
* Assert, Trap, etc macros
1996-10-31 08:10:14 +01:00
* ----------------------------------------------------------------
*/
/*
* Exception Handling definitions
*/
typedef char *ExcMessage;
typedef struct Exception
{
ExcMessage message;
} Exception;
1996-10-31 08:10:14 +01:00
/*
* USE_ASSERT_CHECKING, if defined, turns on all the assertions.
1996-10-31 08:10:14 +01:00
* - plai 9/5/90
*
* It should _NOT_ be defined in releases or in benchmark copies
1996-10-31 08:10:14 +01:00
*/
/*
1999-05-25 18:15:34 +02:00
* Trap
* Generates an exception if the given condition is true.
1996-10-31 08:10:14 +01:00
*
*/
#define Trap(condition, exception) \
{ if ((assert_enabled) && (condition)) \
ExceptionalCondition(CppAsString(condition), &(exception), \
(char*)NULL, __FILE__, __LINE__); }
1996-10-31 08:10:14 +01:00
/*
* TrapMacro is the same as Trap but it's intended for use in macros:
1996-10-31 08:10:14 +01:00
*
* #define foo(x) (AssertM(x != 0) && bar(x))
1996-10-31 08:10:14 +01:00
*
* Isn't CPP fun?
1996-10-31 08:10:14 +01:00
*/
#define TrapMacro(condition, exception) \
((bool) ((! assert_enabled) || (! condition) || \
(ExceptionalCondition(CppAsString(condition), \
&(exception), \
(char*) NULL, __FILE__, __LINE__))))
1998-04-06 19:27:54 +02:00
#ifndef USE_ASSERT_CHECKING
1996-10-31 08:10:14 +01:00
#define Assert(condition)
1998-06-20 06:34:31 +02:00
#define AssertMacro(condition) (void)true
1996-10-31 08:10:14 +01:00
#define AssertArg(condition)
#define AssertState(condition)
#define assert_enabled 0
1996-10-31 08:10:14 +01:00
#else
#define Assert(condition) \
Trap(!(condition), FailedAssertion)
1996-10-31 08:10:14 +01:00
#define AssertMacro(condition) \
(void)TrapMacro(!(condition), FailedAssertion)
1996-10-31 08:10:14 +01:00
#define AssertArg(condition) \
Trap(!(condition), BadArg)
1996-10-31 08:10:14 +01:00
#define AssertState(condition) \
Trap(!(condition), BadState)
1996-10-31 08:10:14 +01:00
extern int assert_enabled;
#endif /* USE_ASSERT_CHECKING */
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* LogTrap
* Generates an exception with a message if the given condition is true.
1996-10-31 08:10:14 +01:00
*
*/
#define LogTrap(condition, exception, printArgs) \
{ if ((assert_enabled) && (condition)) \
ExceptionalCondition(CppAsString(condition), &(exception), \
1999-06-19 07:00:30 +02:00
vararg_format printArgs, __FILE__, __LINE__); }
1996-10-31 08:10:14 +01:00
/*
* LogTrapMacro is the same as LogTrap but it's intended for use in macros:
1996-10-31 08:10:14 +01:00
*
* #define foo(x) (LogAssertMacro(x != 0, "yow!") && bar(x))
1996-10-31 08:10:14 +01:00
*/
#define LogTrapMacro(condition, exception, printArgs) \
((bool) ((! assert_enabled) || (! condition) || \
(ExceptionalCondition(CppAsString(condition), \
&(exception), \
1999-06-19 07:00:30 +02:00
vararg_format printArgs, __FILE__, __LINE__))))
1998-04-06 19:27:54 +02:00
#ifndef USE_ASSERT_CHECKING
1996-10-31 08:10:14 +01:00
#define LogAssert(condition, printArgs)
#define LogAssertMacro(condition, printArgs) true
#define LogAssertArg(condition, printArgs)
#define LogAssertState(condition, printArgs)
#else
#define LogAssert(condition, printArgs) \
LogTrap(!(condition), FailedAssertion, printArgs)
1996-10-31 08:10:14 +01:00
#define LogAssertMacro(condition, printArgs) \
LogTrapMacro(!(condition), FailedAssertion, printArgs)
1996-10-31 08:10:14 +01:00
#define LogAssertArg(condition, printArgs) \
LogTrap(!(condition), BadArg, printArgs)
1996-10-31 08:10:14 +01:00
#define LogAssertState(condition, printArgs) \
LogTrap(!(condition), BadState, printArgs)
1996-10-31 08:10:14 +01:00
extern int assertEnable(int val);
#ifdef ASSERT_CHECKING_TEST
extern int assertTest(int val);
#endif
#endif /* USE_ASSERT_CHECKING */
1996-10-31 08:10:14 +01:00
/* ----------------------------------------------------------------
* Section 8: Min, Max, Abs macros
1996-10-31 08:10:14 +01:00
* ----------------------------------------------------------------
*/
/*
1999-05-25 18:15:34 +02:00
* Max
* Return the maximum of two numbers.
1996-10-31 08:10:14 +01:00
*/
#define Max(x, y) ((x) > (y) ? (x) : (y))
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* Min
* Return the minimum of two numbers.
1996-10-31 08:10:14 +01:00
*/
#define Min(x, y) ((x) < (y) ? (x) : (y))
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* Abs
* Return the absolute value of the argument.
1996-10-31 08:10:14 +01:00
*/
#define Abs(x) ((x) >= 0 ? (x) : -(x))
1996-10-31 08:10:14 +01:00
/*
1999-05-25 18:15:34 +02:00
* StrNCpy
* Does string copy, and forces terminating NULL
*/
/* we do this so if the macro is used in an if action, it will work */
1997-10-25 04:14:22 +02:00
#define StrNCpy(dst,src,len) \
1998-03-31 17:53:51 +02:00
( \
((len) > 0) ? \
( \
strncpy((dst),(src),(len)-1), \
*((dst)+(len)-1)='\0' \
) \
: \
(dummyret)NULL,(void)(dst) \
)
1998-02-11 22:38:08 +01:00
/* Get a bit mask of the bits set in non-int32 aligned addresses */
#define INT_ALIGN_MASK (sizeof(int32) - 1)
1998-02-11 22:45:40 +01:00
/*
* This function gets call too often, so we inline it if we can.
* Are we aligned for int32?
1998-02-11 22:45:40 +01:00
* We have to cast the pointer to int so we can do the AND
* We got the 64 number by testing this against the stock memset() on
* BSD/OS 3.0. Larger values were slower.
1998-02-11 22:45:40 +01:00
*/
1997-11-10 06:10:50 +01:00
#define MemSet(start, val, len) do \
1998-02-12 02:50:01 +01:00
{ \
1998-02-11 22:38:08 +01:00
if (((long)(start) & INT_ALIGN_MASK) == 0 && \
((len) & INT_ALIGN_MASK) == 0 && \
1997-09-18 16:21:02 +02:00
(val) == 0 && \
1997-09-18 19:06:21 +02:00
(len) <= 64) \
1997-09-18 16:21:02 +02:00
{ \
1997-09-18 20:48:32 +02:00
int32 *_i = (int32 *)(start); \
int32 *_stop = (int32 *)((char *)(start) + (len)); \
1997-09-18 16:21:02 +02:00
\
1997-09-18 20:48:32 +02:00
while (_i < _stop) \
*_i++ = 0; \
1997-09-18 16:21:02 +02:00
} \
else \
memset((start), (val), (len)); \
1997-09-18 19:06:21 +02:00
} while (0)
1997-09-18 16:21:02 +02:00
1996-10-31 08:10:14 +01:00
/* ----------------------------------------------------------------
* Section 9: externs
1996-10-31 08:10:14 +01:00
* ----------------------------------------------------------------
*/
extern Exception FailedAssertion;
extern Exception BadArg;
extern Exception BadState;
1996-10-31 08:10:14 +01:00
/* in utils/error/assert.c */
extern int ExceptionalCondition(char *conditionName,
Exception *exceptionP, char *details,
char *fileName, int lineNumber);
1996-10-31 08:10:14 +01:00
/* ----------------
1999-06-19 07:00:30 +02:00
* vararg_format is used by assert and the exception handling stuff
1996-10-31 08:10:14 +01:00
* ----------------
*/
1999-06-19 07:00:30 +02:00
extern char *vararg_format(const char *fmt,...);
1996-10-31 08:10:14 +01:00
/* ----------------------------------------------------------------
* Section 10: berkeley-specific configuration
1996-10-31 08:10:14 +01:00
*
* this section contains settings which are only relevant to the UC Berkeley
* sites. Other sites can ignore this
* ----------------------------------------------------------------
*/
/* ----------------
* storage managers
1996-10-31 08:10:14 +01:00
*
* These are experimental and are not supported in the code that
* we distribute to other sites.
1996-10-31 08:10:14 +01:00
* ----------------
*/
#ifdef NOT_USED
#define STABLE_MEMORY_STORAGE
1996-10-31 08:10:14 +01:00
#endif
/* ----------------------------------------------------------------
* Section 11: system-specific hacks
1996-10-31 08:10:14 +01:00
*
* This should be limited to things that absolutely have to be
* included in every source file. The changes should be factored
* into a separate file so that changes to one port don't require
* changes to c.h (and everyone recompiling their whole system).
1996-10-31 08:10:14 +01:00
* ----------------------------------------------------------------
*/
#ifdef FIXADE
#if defined(hpux)
#include "port/hpux/fixade.h" /* for unaligned access fixup */
#endif /* hpux */
#endif
1996-10-31 08:10:14 +01:00
#if defined(sun) && defined(sparc) && !defined(__SVR4)
#define memmove(d, s, l) bcopy(s, d, l)
#include <unistd.h>
#include <varargs.h>
1996-10-31 08:10:14 +01:00
#endif
/* These are for things that are one way on Unix and another on NT */
#define NULL_DEV "/dev/null"
#define COPY_CMD "cp"
#define SEP_CHAR '/'
1996-10-31 08:10:14 +01:00
/* defines for dynamic linking on Win32 platform */
#ifdef __CYGWIN32__
#if __GNUC__ && ! defined (__declspec)
#error You need egcs 1.1 or newer for compiling!
#endif
#ifdef BUILDING_DLL
#define DLLIMPORT __declspec (dllexport)
1999-05-25 18:15:34 +02:00
#else /* not BUILDING_DLL */
#define DLLIMPORT __declspec (dllimport)
#endif
1999-05-25 18:15:34 +02:00
#else /* not CYGWIN */
#define DLLIMPORT
#endif
/* Provide prototypes for routines not present in a particular machine's
1999-05-25 18:15:34 +02:00
* standard C library. It'd be better to put these in config.h, but
* in config.h we haven't yet included anything that defines size_t...
*/
#ifndef HAVE_SNPRINTF
1999-05-25 18:15:34 +02:00
extern int snprintf(char *str, size_t count, const char *fmt,...);
#endif
#ifndef HAVE_VSNPRINTF
1999-05-25 18:15:34 +02:00
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
#endif
1996-10-31 08:10:14 +01:00
/* ----------------
* end of c.h
1996-10-31 08:10:14 +01:00
* ----------------
*/
#endif /* C_H */