📄 c.h
字号:
/*------------------------------------------------------------------------- * * c.h * Fundamental C definitions. This is included by every .c file in * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate). * * Note that the definitions here are not intended to be exposed to clients * of the frontend interface libraries --- so we don't worry much about * polluting the namespace with lots of stuff... * * * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * $PostgreSQL: pgsql/src/include/c.h,v 1.222.2.1 2008/02/23 19:11:55 tgl Exp $ * *------------------------------------------------------------------------- *//* *---------------------------------------------------------------- * TABLE OF CONTENTS * * When adding stuff to this file, please try to put stuff * into the relevant section, or add new sections as appropriate. * * section description * ------- ------------------------------------------------ * 0) pg_config.h and standard system headers * 1) hacks to cope with non-ANSI C compilers * 2) bool, true, false, TRUE, FALSE, NULL * 3) standard system types * 4) IsValid macros for system types * 5) offsetof, lengthof, endof, alignment * 6) widely useful macros * 7) random stuff * 8) system-specific hacks * * NOTE: since this file is included by both frontend and backend modules, it's * almost certainly wrong to put an "extern" declaration here. typedefs and * macros are the kind of thing that might go here. * *---------------------------------------------------------------- */#ifndef C_H#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 "pg_config.h"#include "pg_config_manual.h"#if !defined(WIN32) && !defined(__CYGWIN__)#include "pg_config_os.h" #endif#include "postgres_ext.h"#include "pg_trace.h"*/#ifndef NAMEDATALEN#define NAMEDATALEN 64#endif#if _MSC_VER >= 1400#define errcode __msvc_errcode#include <crtdefs.h>#undef errcode#endif#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stddef.h>#include <stdarg.h>#ifdef HAVE_STRINGS_H#include <strings.h>#endif#include <sys/types.h>#include <errno.h>#if defined(WIN32) || defined(__CYGWIN__)#include <fcntl.h> /* ensure O_BINARY is available */#endif#ifdef HAVE_SUPPORTDEFS_H#include <SupportDefs.h>#endif#if defined(WIN32) || defined(__CYGWIN__)/* We have to redefine some system functions after they are included above. */#include "pg_config_os.h"#endif/* Must be before gettext() games below */#include <locale.h>#define _(x) gettext((x))#ifdef ENABLE_NLS#include <libintl.h>#else#define gettext(x) (x)#endif/* * Use this to mark strings to be translated by gettext, in places where * you don't want an actual function call to occur (eg, constant tables). */#define gettext_noop(x) (x)/* ---------------------------------------------------------------- * Section 1: hacks to cope with non-ANSI C compilers * * type prefixes (const, signed, volatile, inline) are handled in pg_config.h. * ---------------------------------------------------------------- *//* * CppAsString * Convert the argument to a string, using the C preprocessor. * 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. */#if defined(HAVE_STRINGIZE)#define CppAsString(identifier) #identifier#define CppConcat(x, y) x##y#else /* !HAVE_STRINGIZE */#define CppAsString(identifier) "identifier"/* * 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. */#define _priv_CppIdentity(x)x#define CppConcat(x, y) _priv_CppIdentity(x)y#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 */#ifdef __GNUC__ /* GNU cc */#define dummyret void#else#define dummyret char#endif#ifndef __GNUC__#define __attribute__(_arg_)#endif/* ---------------------------------------------------------------- * Section 2: bool, true, false, TRUE, FALSE, NULL * ---------------------------------------------------------------- *//* * bool * Boolean value, either true or false. * * XXX for C++ compilers, we assume the compiler has a compatible * built-in definition of bool. */#ifndef __cplusplus#ifndef booltypedef char bool;#endif#ifndef true#define true ((bool) 1)#endif#ifndef false#define false ((bool) 0)#endif#endif /* not C++ */typedef bool *BoolPtr;#ifndef TRUE#define TRUE 1#endif#ifndef FALSE#define FALSE 0#endif/* * NULL * Null pointer. */#ifndef NULL#define NULL ((void *) 0)#endif/* ---------------------------------------------------------------- * Section 3: standard system types * ---------------------------------------------------------------- *//* * 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;/* * intN * Signed integer, EXACTLY N BITS IN SIZE, * used for numerical computations and the * frontend/backend protocol. */#ifndef HAVE_INT8typedef signed char int8; /* == 8 bits */typedef signed short int16; /* == 16 bits */typedef signed int int32; /* == 32 bits */#endif /* not HAVE_INT8 *//* * uintN * Unsigned integer, EXACTLY N BITS IN SIZE, * used for numerical computations and the * frontend/backend protocol. */#ifndef HAVE_UINT8typedef unsigned char uint8; /* == 8 bits */typedef unsigned short uint16; /* == 16 bits */typedef unsigned int uint32; /* == 32 bits */#endif /* not HAVE_UINT8 *//* * bitsN * Unit of bitwise operation, AT LEAST N BITS IN SIZE. */typedef uint8 bits8; /* >= 8 bits */typedef uint16 bits16; /* >= 16 bits */typedef uint32 bits32; /* >= 32 bits *//* * floatN * Floating point number, AT LEAST N BITS IN SIZE, * used for numerical computations. * * Since sizeof(floatN) may be > sizeof(char *), always pass * floatN by reference. * * XXX: these typedefs are now deprecated in favor of float4 and float8. * They will eventually go away. */typedef float float32data;typedef double float64data;typedef float *float32;typedef double *float64;/* * 64-bit integers */#ifdef HAVE_LONG_INT_64/* Plain "long int" fits, use it */#ifndef HAVE_INT64typedef long int int64;#endif#ifndef HAVE_UINT64typedef unsigned long int uint64;#endif#elif defined(HAVE_LONG_LONG_INT_64)/* We have working support for "long long int", use that */#ifndef HAVE_INT64typedef long long int int64;#endif#ifndef HAVE_UINT64typedef unsigned long long int uint64;#endif#else /* not HAVE_LONG_INT_64 and not * HAVE_LONG_LONG_INT_64 *//* Won't actually work, but fall back to long int so that code compiles */#ifndef HAVE_INT64typedef long int int64;#endif#ifndef HAVE_UINT64typedef unsigned long int uint64;#endif#define INT64_IS_BUSTED#endif /* not HAVE_LONG_INT_64 and not * HAVE_LONG_LONG_INT_64 *//* Decide if we need to decorate 64-bit constants */#ifdef HAVE_LL_CONSTANTS#define INT64CONST(x) ((int64) x##LL)#define UINT64CONST(x) ((uint64) x##ULL)#else#define INT64CONST(x) ((int64) x)#define UINT64CONST(x) ((uint64) x)#endif/* Select timestamp representation (float8 or int64) */#if defined(USE_INTEGER_DATETIMES) && !defined(INT64_IS_BUSTED)#define HAVE_INT64_TIMESTAMP#endif/* sig_atomic_t is required by ANSI C, but may be missing on old platforms */#ifndef HAVE_SIG_ATOMIC_Ttypedef int sig_atomic_t;#endif/* * Size * Size of any memory resident object, as returned by sizeof. */typedef size_t Size;/* * Index * Index into any memory resident array. * * Note: * Indices are non negative. */typedef unsigned int Index;/* * Offset * Offset into any memory resident array. * * Note: * This differs from an Index in that an Index is always * non negative, whereas Offset may be negative. */typedef signed int Offset;/* * Common Postgres datatype names (as used in the catalogs) */typedef int16 int2;typedef int32 int4;typedef float float4;typedef double float8;/* * Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId, * CommandId *//* typedef Oid is in postgres_ext.h *//* * regproc is the type name used in the include/catalog headers, but * RegProcedure is the preferred name in C code. *//*typedef Oid regproc;typedef regproc RegProcedure;typedef uint32 TransactionId;typedef uint32 LocalTransactionId;typedef uint32 SubTransactionId;*/#define InvalidSubTransactionId ((SubTransactionId) 0)#define TopSubTransactionId ((SubTransactionId) 1)/*typedef TransactionId MultiXactId;typedef uint32 MultiXactOffset;typedef uint32 CommandId;*/#define FirstCommandId ((CommandId) 0)/* * Array indexing support */#define MAXDIM 6typedef struct{ int indx[MAXDIM];} IntArray;/* ---------------- * Variable-length datatypes all share the 'struct varlena' header. * 变长数据类型都是共享的 'struct varlena'头 * * NOTE: for TOASTable types, this is an oversimplification, since the value * may be compressed or moved out-of-line. However datatype-specific routines * are mostly content to deal with de-TOASTed values only, and of course * client-side routines should never see a TOASTed value. But even in a * de-TOASTed value, beware of touching vl_len_ directly, as its representation * is no longer convenient. It's recommended that code always use the VARDATA, * VARSIZE, and SET_VARSIZE macros instead of relying on direct mentions of * the struct fields. See postgres.h for details of the TOASTed form. * ---------------- */struct varlena
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -