Eneboo - Documentación para desarrolladores
|
00001 /*------------------------------------------------------------------------- 00002 * 00003 * c.h 00004 * Fundamental C definitions. This is included by every .c file in 00005 * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate). 00006 * 00007 * Note that the definitions here are not intended to be exposed to clients 00008 * of the frontend interface libraries --- so we don't worry much about 00009 * polluting the namespace with lots of stuff... 00010 * 00011 * 00012 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group 00013 * Portions Copyright (c) 1994, Regents of the University of California 00014 * 00015 * $PostgreSQL: pgsql/src/include/c.h,v 1.190.2.2 2006/05/21 20:05:50 tgl Exp $ 00016 * 00017 *------------------------------------------------------------------------- 00018 */ 00019 /* 00020 *---------------------------------------------------------------- 00021 * TABLE OF CONTENTS 00022 * 00023 * When adding stuff to this file, please try to put stuff 00024 * into the relevant section, or add new sections as appropriate. 00025 * 00026 * section description 00027 * ------- ------------------------------------------------ 00028 * 0) pg_config.h and standard system headers 00029 * 1) hacks to cope with non-ANSI C compilers 00030 * 2) bool, true, false, TRUE, FALSE, NULL 00031 * 3) standard system types 00032 * 4) IsValid macros for system types 00033 * 5) offsetof, lengthof, endof, alignment 00034 * 6) widely useful macros 00035 * 7) random stuff 00036 * 8) system-specific hacks 00037 * 00038 * NOTE: since this file is included by both frontend and backend modules, it's 00039 * almost certainly wrong to put an "extern" declaration here. typedefs and 00040 * macros are the kind of thing that might go here. 00041 * 00042 *---------------------------------------------------------------- 00043 */ 00044 #ifndef C_H 00045 #define C_H 00046 00047 /* 00048 * We have to include stdlib.h here because it defines many of these macros 00049 * on some platforms, and we only want our definitions used if stdlib.h doesn't 00050 * have its own. The same goes for stddef and stdarg if present. 00051 */ 00052 00053 #include "pg_config.h" 00054 #include "pg_config_manual.h" /* must be after pg_config.h */ 00055 #if !defined(WIN32) && !defined(__CYGWIN__) 00056 #include "pg_config_os.h" /* must be before any system header files */ 00057 #else 00058 #if defined(_MSC_VER) || defined(__BORLANDC__) 00059 #define WIN32_CLIENT_ONLY 00060 #endif 00061 #endif 00062 #include "postgres_ext.h" 00063 00064 #include <stdio.h> 00065 #include <stdlib.h> 00066 #include <string.h> 00067 #include <stddef.h> 00068 #include <stdarg.h> 00069 #ifdef HAVE_STRINGS_H 00070 #include <strings.h> 00071 #endif 00072 #include <sys/types.h> 00073 00074 #include <errno.h> 00075 #if defined(WIN32) || defined(__CYGWIN__) 00076 #include <fcntl.h> /* ensure O_BINARY is available */ 00077 #endif 00078 #ifdef HAVE_SUPPORTDEFS_H 00079 #include <SupportDefs.h> 00080 #endif 00081 00082 #if defined(WIN32) || defined(__CYGWIN__) 00083 #ifndef WIN32_CLIENT_ONLY 00084 /* We have to redefine some system functions after they are included above */ 00085 #include "pg_config_os.h" 00086 #else 00087 #include "port/win32.h" /* We didn't run configure, but this is our 00088 * port file */ 00089 #endif 00090 #endif 00091 00092 /* Must be before gettext() games below */ 00093 #include <locale.h> 00094 00095 #define _(x) gettext((x)) 00096 00097 #ifdef ENABLE_NLS 00098 #include <libintl.h> 00099 #else 00100 #define gettext(x) (x) 00101 #endif 00102 00103 /* 00104 * Use this to mark strings to be translated by gettext, in places where 00105 * you don't want an actual function call to occur (eg, constant tables). 00106 */ 00107 #define gettext_noop(x) (x) 00108 00109 00110 /* ---------------------------------------------------------------- 00111 * Section 1: hacks to cope with non-ANSI C compilers 00112 * 00113 * type prefixes (const, signed, volatile, inline) are handled in pg_config.h. 00114 * ---------------------------------------------------------------- 00115 */ 00116 00117 /* 00118 * CppAsString 00119 * Convert the argument to a string, using the C preprocessor. 00120 * CppConcat 00121 * Concatenate two arguments together, using the C preprocessor. 00122 * 00123 * Note: the standard Autoconf macro AC_C_STRINGIZE actually only checks 00124 * whether #identifier works, but if we have that we likely have ## too. 00125 */ 00126 #if defined(HAVE_STRINGIZE) 00127 00128 #define CppAsString(identifier) #identifier 00129 #define CppConcat(x, y) x##y 00130 #else /* !HAVE_STRINGIZE */ 00131 00132 #define CppAsString(identifier) "identifier" 00133 00134 /* 00135 * CppIdentity -- On Reiser based cpp's this is used to concatenate 00136 * two tokens. That is 00137 * CppIdentity(A)B ==> AB 00138 * We renamed it to _private_CppIdentity because it should not 00139 * be referenced outside this file. On other cpp's it 00140 * produces A B. 00141 */ 00142 #define _priv_CppIdentity(x)x 00143 #define CppConcat(x, y) _priv_CppIdentity(x)y 00144 #endif /* !HAVE_STRINGIZE */ 00145 00146 /* 00147 * dummyret is used to set return values in macros that use ?: to make 00148 * assignments. gcc wants these to be void, other compilers like char 00149 */ 00150 #ifdef __GNUC__ /* GNU cc */ 00151 #define dummyret void 00152 #else 00153 #define dummyret char 00154 #endif 00155 00156 #ifndef __GNUC__ 00157 #define __attribute__(_arg_) 00158 #endif 00159 00160 /* ---------------------------------------------------------------- 00161 * Section 2: bool, true, false, TRUE, FALSE, NULL 00162 * ---------------------------------------------------------------- 00163 */ 00164 00165 /* 00166 * bool 00167 * Boolean value, either true or false. 00168 * 00169 * XXX for C++ compilers, we assume the compiler has a compatible 00170 * built-in definition of bool. 00171 */ 00172 00173 /* BeOS defines bool already, but the compiler chokes on the 00174 * #ifndef unless we wrap it in this check. 00175 */ 00176 #ifndef __BEOS__ 00177 00178 #ifndef __cplusplus 00179 00180 #ifndef bool 00181 typedef char bool; 00182 #endif 00183 00184 #ifndef true 00185 #define true ((bool) 1) 00186 #endif 00187 00188 #ifndef false 00189 #define false ((bool) 0) 00190 #endif 00191 #endif /* not C++ */ 00192 #endif /* __BEOS__ */ 00193 00194 typedef bool *BoolPtr; 00195 00196 #ifndef TRUE 00197 #define TRUE 1 00198 #endif 00199 00200 #ifndef FALSE 00201 #define FALSE 0 00202 #endif 00203 00204 /* 00205 * NULL 00206 * Null pointer. 00207 */ 00208 #ifndef NULL 00209 #define NULL ((void *) 0) 00210 #endif 00211 00212 00213 /* ---------------------------------------------------------------- 00214 * Section 3: standard system types 00215 * ---------------------------------------------------------------- 00216 */ 00217 00218 /* 00219 * Pointer 00220 * Variable holding address of any memory resident object. 00221 * 00222 * XXX Pointer arithmetic is done with this, so it can't be void * 00223 * under "true" ANSI compilers. 00224 */ 00225 typedef char *Pointer; 00226 00227 /* 00228 * intN 00229 * Signed integer, EXACTLY N BITS IN SIZE, 00230 * used for numerical computations and the 00231 * frontend/backend protocol. 00232 */ 00233 #ifndef HAVE_INT8 00234 typedef signed char int8; /* == 8 bits */ 00235 typedef signed short int16; /* == 16 bits */ 00236 typedef signed int int32; /* == 32 bits */ 00237 #endif /* not HAVE_INT8 */ 00238 00239 /* 00240 * uintN 00241 * Unsigned integer, EXACTLY N BITS IN SIZE, 00242 * used for numerical computations and the 00243 * frontend/backend protocol. 00244 */ 00245 #ifndef HAVE_UINT8 00246 typedef unsigned char uint8; /* == 8 bits */ 00247 typedef unsigned short uint16; /* == 16 bits */ 00248 typedef unsigned int uint32; /* == 32 bits */ 00249 #endif /* not HAVE_UINT8 */ 00250 00251 /* 00252 * bitsN 00253 * Unit of bitwise operation, AT LEAST N BITS IN SIZE. 00254 */ 00255 typedef uint8 bits8; /* >= 8 bits */ 00256 typedef uint16 bits16; /* >= 16 bits */ 00257 typedef uint32 bits32; /* >= 32 bits */ 00258 00259 /* 00260 * floatN 00261 * Floating point number, AT LEAST N BITS IN SIZE, 00262 * used for numerical computations. 00263 * 00264 * Since sizeof(floatN) may be > sizeof(char *), always pass 00265 * floatN by reference. 00266 * 00267 * XXX: these typedefs are now deprecated in favor of float4 and float8. 00268 * They will eventually go away. 00269 */ 00270 typedef float float32data; 00271 typedef double float64data; 00272 typedef float *float32; 00273 typedef double *float64; 00274 00275 /* 00276 * 64-bit integers 00277 */ 00278 #ifdef HAVE_LONG_INT_64 00279 /* Plain "long int" fits, use it */ 00280 00281 #ifndef HAVE_INT64 00282 typedef long int int64; 00283 #endif 00284 #ifndef HAVE_UINT64 00285 typedef unsigned long int uint64; 00286 #endif 00287 #elif defined(HAVE_LONG_LONG_INT_64) 00288 /* We have working support for "long long int", use that */ 00289 00290 #ifndef HAVE_INT64 00291 typedef long long int int64; 00292 #endif 00293 #ifndef HAVE_UINT64 00294 typedef unsigned long long int uint64; 00295 #endif 00296 #else /* not HAVE_LONG_INT_64 and not 00297 * HAVE_LONG_LONG_INT_64 */ 00298 00299 /* Won't actually work, but fall back to long int so that code compiles */ 00300 #ifndef HAVE_INT64 00301 typedef long int int64; 00302 #endif 00303 #ifndef HAVE_UINT64 00304 typedef unsigned long int uint64; 00305 #endif 00306 00307 #define INT64_IS_BUSTED 00308 #endif /* not HAVE_LONG_INT_64 and not 00309 * HAVE_LONG_LONG_INT_64 */ 00310 00311 /* Decide if we need to decorate 64-bit constants */ 00312 #ifdef HAVE_LL_CONSTANTS 00313 #define INT64CONST(x) ((int64) x##LL) 00314 #define UINT64CONST(x) ((uint64) x##ULL) 00315 #else 00316 #define INT64CONST(x) ((int64) x) 00317 #define UINT64CONST(x) ((uint64) x) 00318 #endif 00319 00320 00321 /* Select timestamp representation (float8 or int64) */ 00322 #if defined(USE_INTEGER_DATETIMES) && !defined(INT64_IS_BUSTED) 00323 #define HAVE_INT64_TIMESTAMP 00324 #endif 00325 00326 /* sig_atomic_t is required by ANSI C, but may be missing on old platforms */ 00327 #ifndef HAVE_SIG_ATOMIC_T 00328 typedef int sig_atomic_t; 00329 #endif 00330 00331 /* 00332 * Size 00333 * Size of any memory resident object, as returned by sizeof. 00334 */ 00335 typedef size_t Size; 00336 00337 /* 00338 * Index 00339 * Index into any memory resident array. 00340 * 00341 * Note: 00342 * Indices are non negative. 00343 */ 00344 typedef unsigned int Index; 00345 00346 /* 00347 * Offset 00348 * Offset into any memory resident array. 00349 * 00350 * Note: 00351 * This differs from an Index in that an Index is always 00352 * non negative, whereas Offset may be negative. 00353 */ 00354 typedef signed int Offset; 00355 00356 /* 00357 * Common Postgres datatype names (as used in the catalogs) 00358 */ 00359 typedef int16 int2; 00360 typedef int32 int4; 00361 typedef float float4; 00362 typedef double float8; 00363 00364 /* 00365 * Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId, 00366 * CommandId 00367 */ 00368 00369 /* typedef Oid is in postgres_ext.h */ 00370 00371 /* 00372 * regproc is the type name used in the include/catalog headers, but 00373 * RegProcedure is the preferred name in C code. 00374 */ 00375 typedef Oid regproc; 00376 typedef regproc RegProcedure; 00377 00378 typedef uint32 TransactionId; 00379 00380 typedef uint32 SubTransactionId; 00381 00382 #define InvalidSubTransactionId ((SubTransactionId) 0) 00383 #define TopSubTransactionId ((SubTransactionId) 1) 00384 00385 /* MultiXactId must be equivalent to TransactionId, to fit in t_xmax */ 00386 typedef TransactionId MultiXactId; 00387 00388 typedef uint32 MultiXactOffset; 00389 00390 typedef uint32 CommandId; 00391 00392 #define FirstCommandId ((CommandId) 0) 00393 00394 /* 00395 * Array indexing support 00396 */ 00397 #define MAXDIM 6 00398 typedef struct 00399 { 00400 int indx[MAXDIM]; 00401 } IntArray; 00402 00403 /* ---------------- 00404 * Variable-length datatypes all share the 'struct varlena' header. 00405 * 00406 * NOTE: for TOASTable types, this is an oversimplification, since the value 00407 * may be compressed or moved out-of-line. However datatype-specific routines 00408 * are mostly content to deal with de-TOASTed values only, and of course 00409 * client-side routines should never see a TOASTed value. See postgres.h for 00410 * details of the TOASTed form. 00411 * ---------------- 00412 */ 00413 struct varlena 00414 { 00415 int32 vl_len; 00416 char vl_dat[1]; 00417 }; 00418 00419 #define VARHDRSZ ((int32) sizeof(int32)) 00420 00421 /* 00422 * These widely-used datatypes are just a varlena header and the data bytes. 00423 * There is no terminating null or anything like that --- the data length is 00424 * always VARSIZE(ptr) - VARHDRSZ. 00425 */ 00426 typedef struct varlena bytea; 00427 typedef struct varlena text; 00428 typedef struct varlena BpChar; /* blank-padded char, ie SQL char(n) */ 00429 typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */ 00430 00431 /* 00432 * Specialized array types. These are physically laid out just the same 00433 * as regular arrays (so that the regular array subscripting code works 00434 * with them). They exist as distinct types mostly for historical reasons: 00435 * they have nonstandard I/O behavior which we don't want to change for fear 00436 * of breaking applications that look at the system catalogs. There is also 00437 * an implementation issue for oidvector: it's part of the primary key for 00438 * pg_proc, and we can't use the normal btree array support routines for that 00439 * without circularity. 00440 */ 00441 typedef struct 00442 { 00443 int32 size; /* these fields must match ArrayType! */ 00444 int ndim; 00445 int flags; 00446 Oid elemtype; 00447 int dim1; 00448 int lbound1; 00449 int2 values[1]; /* VARIABLE LENGTH ARRAY */ 00450 } int2vector; /* VARIABLE LENGTH STRUCT */ 00451 00452 typedef struct 00453 { 00454 int32 size; /* these fields must match ArrayType! */ 00455 int ndim; 00456 int flags; 00457 Oid elemtype; 00458 int dim1; 00459 int lbound1; 00460 Oid values[1]; /* VARIABLE LENGTH ARRAY */ 00461 } oidvector; /* VARIABLE LENGTH STRUCT */ 00462 00463 /* 00464 * We want NameData to have length NAMEDATALEN and int alignment, 00465 * because that's how the data type 'name' is defined in pg_type. 00466 * Use a union to make sure the compiler agrees. Note that NAMEDATALEN 00467 * must be a multiple of sizeof(int), else sizeof(NameData) will probably 00468 * not come out equal to NAMEDATALEN. 00469 */ 00470 typedef union nameData 00471 { 00472 char data[NAMEDATALEN]; 00473 int alignmentDummy; 00474 } NameData; 00475 typedef NameData *Name; 00476 00477 #define NameStr(name) ((name).data) 00478 00479 #define SQL_STR_DOUBLE(ch) ((ch) == '\'' || (ch) == '\\') 00480 #define ESCAPE_STRING_SYNTAX 'E' 00481 00482 /* ---------------------------------------------------------------- 00483 * Section 4: IsValid macros for system types 00484 * ---------------------------------------------------------------- 00485 */ 00486 /* 00487 * BoolIsValid 00488 * True iff bool is valid. 00489 */ 00490 #define BoolIsValid(boolean) ((boolean) == false || (boolean) == true) 00491 00492 /* 00493 * PointerIsValid 00494 * True iff pointer is valid. 00495 */ 00496 #define PointerIsValid(pointer) ((void*)(pointer) != NULL) 00497 00498 /* 00499 * PointerIsAligned 00500 * True iff pointer is properly aligned to point to the given type. 00501 */ 00502 #define PointerIsAligned(pointer, type) \ 00503 (((long)(pointer) % (sizeof (type))) == 0) 00504 00505 #define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid)) 00506 00507 #define RegProcedureIsValid(p) OidIsValid(p) 00508 00509 00510 /* ---------------------------------------------------------------- 00511 * Section 5: offsetof, lengthof, endof, alignment 00512 * ---------------------------------------------------------------- 00513 */ 00514 /* 00515 * offsetof 00516 * Offset of a structure/union field within that structure/union. 00517 * 00518 * XXX This is supposed to be part of stddef.h, but isn't on 00519 * some systems (like SunOS 4). 00520 */ 00521 #ifndef offsetof 00522 #define offsetof(type, field) ((long) &((type *)0)->field) 00523 #endif /* offsetof */ 00524 00525 /* 00526 * lengthof 00527 * Number of elements in an array. 00528 */ 00529 #define lengthof(array) (sizeof (array) / sizeof ((array)[0])) 00530 00531 /* 00532 * endof 00533 * Address of the element one past the last in an array. 00534 */ 00535 #define endof(array) (&(array)[lengthof(array)]) 00536 00537 /* ---------------- 00538 * Alignment macros: align a length or address appropriately for a given type. 00539 * 00540 * There used to be some incredibly crufty platform-dependent hackery here, 00541 * but now we rely on the configure script to get the info for us. Much nicer. 00542 * 00543 * NOTE: TYPEALIGN will not work if ALIGNVAL is not a power of 2. 00544 * That case seems extremely unlikely to occur in practice, however. 00545 * ---------------- 00546 */ 00547 00548 #define TYPEALIGN(ALIGNVAL,LEN) \ 00549 (((long) (LEN) + ((ALIGNVAL) - 1)) & ~((long) ((ALIGNVAL) - 1))) 00550 00551 #define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN)) 00552 #define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN)) 00553 #define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN)) 00554 #define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN)) 00555 #define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN)) 00556 /* MAXALIGN covers only built-in types, not buffers */ 00557 #define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN)) 00558 00559 00560 /* ---------------------------------------------------------------- 00561 * Section 6: widely useful macros 00562 * ---------------------------------------------------------------- 00563 */ 00564 /* 00565 * Max 00566 * Return the maximum of two numbers. 00567 */ 00568 #define Max(x, y) ((x) > (y) ? (x) : (y)) 00569 00570 /* 00571 * Min 00572 * Return the minimum of two numbers. 00573 */ 00574 #define Min(x, y) ((x) < (y) ? (x) : (y)) 00575 00576 /* 00577 * Abs 00578 * Return the absolute value of the argument. 00579 */ 00580 #define Abs(x) ((x) >= 0 ? (x) : -(x)) 00581 00582 /* 00583 * StrNCpy 00584 * Like standard library function strncpy(), except that result string 00585 * is guaranteed to be null-terminated --- that is, at most N-1 bytes 00586 * of the source string will be kept. 00587 * Also, the macro returns no result (too hard to do that without 00588 * evaluating the arguments multiple times, which seems worse). 00589 * 00590 * BTW: when you need to copy a non-null-terminated string (like a text 00591 * datum) and add a null, do not do it with StrNCpy(..., len+1). That 00592 * might seem to work, but it fetches one byte more than there is in the 00593 * text object. One fine day you'll have a SIGSEGV because there isn't 00594 * another byte before the end of memory. Don't laugh, we've had real 00595 * live bug reports from real live users over exactly this mistake. 00596 * Do it honestly with "memcpy(dst,src,len); dst[len] = '\0';", instead. 00597 */ 00598 #define StrNCpy(dst,src,len) \ 00599 do \ 00600 { \ 00601 char * _dst = (dst); \ 00602 Size _len = (len); \ 00603 \ 00604 if (_len > 0) \ 00605 { \ 00606 strncpy(_dst, (src), _len); \ 00607 _dst[_len-1] = '\0'; \ 00608 } \ 00609 } while (0) 00610 00611 00612 /* Get a bit mask of the bits set in non-int32 aligned addresses */ 00613 #define INT_ALIGN_MASK (sizeof(int32) - 1) 00614 00615 /* 00616 * MemSet 00617 * Exactly the same as standard library function memset(), but considerably 00618 * faster for zeroing small word-aligned structures (such as parsetree nodes). 00619 * This has to be a macro because the main point is to avoid function-call 00620 * overhead. However, we have also found that the loop is faster than 00621 * native libc memset() on some platforms, even those with assembler 00622 * memset() functions. More research needs to be done, perhaps with 00623 * platform-specific MEMSET_LOOP_LIMIT values or tests in configure. 00624 * 00625 * bjm 2002-10-08 00626 */ 00627 #define MemSet(start, val, len) \ 00628 do \ 00629 { \ 00630 /* must be void* because we don't know if it is integer aligned yet */ \ 00631 void *_vstart = (void *) (start); \ 00632 int _val = (val); \ 00633 Size _len = (len); \ 00634 \ 00635 if ((((long) _vstart) & INT_ALIGN_MASK) == 0 && \ 00636 (_len & INT_ALIGN_MASK) == 0 && \ 00637 _val == 0 && \ 00638 _len <= MEMSET_LOOP_LIMIT) \ 00639 { \ 00640 int32 *_start = (int32 *) _vstart; \ 00641 int32 *_stop = (int32 *) ((char *) _start + _len); \ 00642 while (_start < _stop) \ 00643 *_start++ = 0; \ 00644 } \ 00645 else \ 00646 memset(_vstart, _val, _len); \ 00647 } while (0) 00648 00649 #define MEMSET_LOOP_LIMIT 1024 00650 00651 /* 00652 * MemSetAligned is the same as MemSet except it omits the test to see if 00653 * "start" is word-aligned. This is okay to use if the caller knows a-priori 00654 * that the pointer is suitably aligned (typically, because he just got it 00655 * from palloc(), which always delivers a max-aligned pointer). 00656 */ 00657 #define MemSetAligned(start, val, len) \ 00658 do \ 00659 { \ 00660 int32 *_start = (int32 *) (start); \ 00661 int _val = (val); \ 00662 Size _len = (len); \ 00663 \ 00664 if ((_len & INT_ALIGN_MASK) == 0 && \ 00665 _val == 0 && \ 00666 _len <= MEMSET_LOOP_LIMIT) \ 00667 { \ 00668 int32 *_stop = (int32 *) ((char *) _start + _len); \ 00669 while (_start < _stop) \ 00670 *_start++ = 0; \ 00671 } \ 00672 else \ 00673 memset(_start, _val, _len); \ 00674 } while (0) 00675 00676 00677 /* 00678 * MemSetTest/MemSetLoop are a variant version that allow all the tests in 00679 * MemSet to be done at compile time in cases where "val" and "len" are 00680 * constants *and* we know the "start" pointer must be word-aligned. 00681 * If MemSetTest succeeds, then it is okay to use MemSetLoop, otherwise use 00682 * MemSetAligned. Beware of multiple evaluations of the arguments when using 00683 * this approach. 00684 */ 00685 #define MemSetTest(val, len) \ 00686 ( ((len) & INT_ALIGN_MASK) == 0 && \ 00687 (len) <= MEMSET_LOOP_LIMIT && \ 00688 (val) == 0 ) 00689 00690 #define MemSetLoop(start, val, len) \ 00691 do \ 00692 { \ 00693 int32 * _start = (int32 *) (start); \ 00694 int32 * _stop = (int32 *) ((char *) _start + (Size) (len)); \ 00695 \ 00696 while (_start < _stop) \ 00697 *_start++ = 0; \ 00698 } while (0) 00699 00700 00701 /* ---------------------------------------------------------------- 00702 * Section 7: random stuff 00703 * ---------------------------------------------------------------- 00704 */ 00705 00706 /* msb for char */ 00707 #define CSIGNBIT (0x80) 00708 #define HIGHBIT (0x80) 00709 #define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT) 00710 00711 #define STATUS_OK (0) 00712 #define STATUS_ERROR (-1) 00713 #define STATUS_EOF (-2) 00714 #define STATUS_FOUND (1) 00715 00716 00717 /* ---------------------------------------------------------------- 00718 * Section 8: system-specific hacks 00719 * 00720 * This should be limited to things that absolutely have to be 00721 * included in every source file. The port-specific header file 00722 * is usually a better place for this sort of thing. 00723 * ---------------------------------------------------------------- 00724 */ 00725 00726 /* 00727 * NOTE: this is also used for opening text files. 00728 * WIN32 treats Control-Z as EOF in files opened in text mode. 00729 * Therefore, we open files in binary mode on Win32 so we can read 00730 * literal control-Z. The other affect is that we see CRLF, but 00731 * that is OK because we can already handle those cleanly. 00732 */ 00733 #if defined(WIN32) || defined(__CYGWIN__) 00734 #define PG_BINARY O_BINARY 00735 #define PG_BINARY_R "rb" 00736 #define PG_BINARY_W "wb" 00737 #else 00738 #define PG_BINARY 0 00739 #define PG_BINARY_R "r" 00740 #define PG_BINARY_W "w" 00741 #endif 00742 00743 #if defined(sun) && defined(__sparc__) && !defined(__SVR4) 00744 #include <unistd.h> 00745 #endif 00746 00747 /* These are for things that are one way on Unix and another on NT */ 00748 #define NULL_DEV "/dev/null" 00749 00750 /* 00751 * Provide prototypes for routines not present in a particular machine's 00752 * standard C library. 00753 */ 00754 00755 #if !HAVE_DECL_SNPRINTF 00756 extern int 00757 snprintf(char *str, size_t count, const char *fmt,...) 00758 /* This extension allows gcc to check the format string */ 00759 __attribute__((format(printf, 3, 4))); 00760 #endif 00761 00762 #if !HAVE_DECL_VSNPRINTF 00763 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args); 00764 #endif 00765 00766 #if !defined(HAVE_MEMMOVE) && !defined(memmove) 00767 #define memmove(d, s, c) bcopy(s, d, c) 00768 #endif 00769 00770 #ifndef DLLIMPORT 00771 #define DLLIMPORT /* no special DLL markers on most ports */ 00772 #endif 00773 00774 /* 00775 * The following is used as the arg list for signal handlers. Any ports 00776 * that take something other than an int argument should override this in 00777 * their pg_config_os.h file. Note that variable names are required 00778 * because it is used in both the prototypes as well as the definitions. 00779 * Note also the long name. We expect that this won't collide with 00780 * other names causing compiler warnings. 00781 */ 00782 00783 #ifndef SIGNAL_ARGS 00784 #define SIGNAL_ARGS int postgres_signal_arg 00785 #endif 00786 00787 /* 00788 * When there is no sigsetjmp, its functionality is provided by plain 00789 * setjmp. Incidentally, nothing provides setjmp's functionality in 00790 * that case. 00791 */ 00792 #ifndef HAVE_SIGSETJMP 00793 #define sigjmp_buf jmp_buf 00794 #define sigsetjmp(x,y) setjmp(x) 00795 #define siglongjmp longjmp 00796 #endif 00797 00798 #if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC 00799 extern int fdatasync(int fildes); 00800 #endif 00801 00802 /* If strtoq() exists, rename it to the more standard strtoll() */ 00803 #if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOLL) && defined(HAVE_STRTOQ) 00804 #define strtoll strtoq 00805 #define HAVE_STRTOLL 1 00806 #endif 00807 00808 /* If strtouq() exists, rename it to the more standard strtoull() */ 00809 #if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOULL) && defined(HAVE_STRTOUQ) 00810 #define strtoull strtouq 00811 #define HAVE_STRTOULL 1 00812 #endif 00813 00814 /* EXEC_BACKEND defines */ 00815 #ifdef EXEC_BACKEND 00816 #define NON_EXEC_STATIC 00817 #else 00818 #define NON_EXEC_STATIC static 00819 #endif 00820 00821 /* /port compatibility functions */ 00822 #include "port.h" 00823 00824 #endif /* C_H */