]> granicus.if.org Git - postgresql/blob - src/include/c.h
Create a type-specific typanalyze routine for tsvector, which collects stats
[postgresql] / src / include / c.h
1 /*-------------------------------------------------------------------------
2  *
3  * c.h
4  *        Fundamental C definitions.  This is included by every .c file in
5  *        PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate).
6  *
7  *        Note that the definitions here are not intended to be exposed to clients
8  *        of the frontend interface libraries --- so we don't worry much about
9  *        polluting the namespace with lots of stuff...
10  *
11  *
12  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
13  * Portions Copyright (c) 1994, Regents of the University of California
14  *
15  * $PostgreSQL: pgsql/src/include/c.h,v 1.229 2008/07/03 02:49:54 momjian Exp $
16  *
17  *-------------------------------------------------------------------------
18  */
19 /*
20  *----------------------------------------------------------------
21  *       TABLE OF CONTENTS
22  *
23  *              When adding stuff to this file, please try to put stuff
24  *              into the relevant section, or add new sections as appropriate.
25  *
26  *        section       description
27  *        -------       ------------------------------------------------
28  *              0)              pg_config.h and standard system headers
29  *              1)              hacks to cope with non-ANSI C compilers
30  *              2)              bool, true, false, TRUE, FALSE, NULL
31  *              3)              standard system types
32  *              4)              IsValid macros for system types
33  *              5)              offsetof, lengthof, endof, alignment
34  *              6)              widely useful macros
35  *              7)              random stuff
36  *              8)              system-specific hacks
37  *
38  * NOTE: since this file is included by both frontend and backend modules, it's
39  * almost certainly wrong to put an "extern" declaration here.  typedefs and
40  * macros are the kind of thing that might go here.
41  *
42  *----------------------------------------------------------------
43  */
44 #ifndef C_H
45 #define C_H
46
47 /*
48  * We have to include stdlib.h here because it defines many of these macros
49  * on some platforms, and we only want our definitions used if stdlib.h doesn't
50  * have its own.  The same goes for stddef and stdarg if present.
51  */
52
53 #include "pg_config.h"
54 #include "pg_config_manual.h"   /* must be after pg_config.h */
55 #if !defined(WIN32) && !defined(__CYGWIN__)             /* win32 will include further
56                                                                                                  * down */
57 #include "pg_config_os.h"               /* must be before any system header files */
58 #endif
59 #include "postgres_ext.h"
60
61 #if _MSC_VER >= 1400
62 #define errcode __msvc_errcode
63 #include <crtdefs.h>
64 #undef errcode
65 #endif
66
67 #include <stdio.h>
68 #include <stdlib.h>
69 #include <string.h>
70 #include <stddef.h>
71 #include <stdarg.h>
72 #ifdef HAVE_STRINGS_H
73 #include <strings.h>
74 #endif
75 #include <sys/types.h>
76
77 #include <errno.h>
78 #if defined(WIN32) || defined(__CYGWIN__)
79 #include <fcntl.h>                              /* ensure O_BINARY is available */
80 #endif
81 #ifdef HAVE_SUPPORTDEFS_H
82 #include <SupportDefs.h>
83 #endif
84
85 #if defined(WIN32) || defined(__CYGWIN__)
86 /* We have to redefine some system functions after they are included above. */
87 #include "pg_config_os.h"
88 #endif
89
90 /* Must be before gettext() games below */
91 #include <locale.h>
92
93 #define _(x) gettext((x))
94
95 #ifdef ENABLE_NLS
96 #include <libintl.h>
97 #else
98 #define gettext(x) (x)
99 #endif
100
101 /*
102  *      Use this to mark string constants as needing translation at some later
103  *      time, rather than immediately.  This is useful for cases where you need
104  *      access to the original string and translated string, and for cases where
105  *      immediate translation is not possible, like when initializing global
106  *      variables.
107  *              http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html
108  */
109 #define gettext_noop(x) (x)
110
111
112 /* ----------------------------------------------------------------
113  *                              Section 1: hacks to cope with non-ANSI C compilers
114  *
115  * type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
116  * ----------------------------------------------------------------
117  */
118
119 /*
120  * CppAsString
121  *              Convert the argument to a string, using the C preprocessor.
122  * CppConcat
123  *              Concatenate two arguments together, using the C preprocessor.
124  *
125  * Note: the standard Autoconf macro AC_C_STRINGIZE actually only checks
126  * whether #identifier works, but if we have that we likely have ## too.
127  */
128 #if defined(HAVE_STRINGIZE)
129
130 #define CppAsString(identifier) #identifier
131 #define CppConcat(x, y)                 x##y
132 #else                                                   /* !HAVE_STRINGIZE */
133
134 #define CppAsString(identifier) "identifier"
135
136 /*
137  * CppIdentity -- On Reiser based cpp's this is used to concatenate
138  *              two tokens.  That is
139  *                              CppIdentity(A)B ==> AB
140  *              We renamed it to _private_CppIdentity because it should not
141  *              be referenced outside this file.  On other cpp's it
142  *              produces  A  B.
143  */
144 #define _priv_CppIdentity(x)x
145 #define CppConcat(x, y)                 _priv_CppIdentity(x)y
146 #endif   /* !HAVE_STRINGIZE */
147
148 /*
149  * dummyret is used to set return values in macros that use ?: to make
150  * assignments.  gcc wants these to be void, other compilers like char
151  */
152 #ifdef __GNUC__                                 /* GNU cc */
153 #define dummyret        void
154 #else
155 #define dummyret        char
156 #endif
157
158 #ifndef __GNUC__
159 #define __attribute__(_arg_)
160 #endif
161
162 /* ----------------------------------------------------------------
163  *                              Section 2:      bool, true, false, TRUE, FALSE, NULL
164  * ----------------------------------------------------------------
165  */
166
167 /*
168  * bool
169  *              Boolean value, either true or false.
170  *
171  * XXX for C++ compilers, we assume the compiler has a compatible
172  * built-in definition of bool.
173  */
174
175 #ifndef __cplusplus
176
177 #ifndef bool
178 typedef char bool;
179 #endif
180
181 #ifndef true
182 #define true    ((bool) 1)
183 #endif
184
185 #ifndef false
186 #define false   ((bool) 0)
187 #endif
188 #endif   /* not C++ */
189
190 typedef bool *BoolPtr;
191
192 #ifndef TRUE
193 #define TRUE    1
194 #endif
195
196 #ifndef FALSE
197 #define FALSE   0
198 #endif
199
200 /*
201  * NULL
202  *              Null pointer.
203  */
204 #ifndef NULL
205 #define NULL    ((void *) 0)
206 #endif
207
208
209 /* ----------------------------------------------------------------
210  *                              Section 3:      standard system types
211  * ----------------------------------------------------------------
212  */
213
214 /*
215  * Pointer
216  *              Variable holding address of any memory resident object.
217  *
218  *              XXX Pointer arithmetic is done with this, so it can't be void *
219  *              under "true" ANSI compilers.
220  */
221 typedef char *Pointer;
222
223 /*
224  * intN
225  *              Signed integer, EXACTLY N BITS IN SIZE,
226  *              used for numerical computations and the
227  *              frontend/backend protocol.
228  */
229 #ifndef HAVE_INT8
230 typedef signed char int8;               /* == 8 bits */
231 typedef signed short int16;             /* == 16 bits */
232 typedef signed int int32;               /* == 32 bits */
233 #endif   /* not HAVE_INT8 */
234
235 /*
236  * uintN
237  *              Unsigned integer, EXACTLY N BITS IN SIZE,
238  *              used for numerical computations and the
239  *              frontend/backend protocol.
240  */
241 #ifndef HAVE_UINT8
242 typedef unsigned char uint8;    /* == 8 bits */
243 typedef unsigned short uint16;  /* == 16 bits */
244 typedef unsigned int uint32;    /* == 32 bits */
245 #endif   /* not HAVE_UINT8 */
246
247 /*
248  * bitsN
249  *              Unit of bitwise operation, AT LEAST N BITS IN SIZE.
250  */
251 typedef uint8 bits8;                    /* >= 8 bits */
252 typedef uint16 bits16;                  /* >= 16 bits */
253 typedef uint32 bits32;                  /* >= 32 bits */
254
255 /*
256  * 64-bit integers
257  */
258 #ifdef HAVE_LONG_INT_64
259 /* Plain "long int" fits, use it */
260
261 #ifndef HAVE_INT64
262 typedef long int int64;
263 #endif
264 #ifndef HAVE_UINT64
265 typedef unsigned long int uint64;
266 #endif
267 #elif defined(HAVE_LONG_LONG_INT_64)
268 /* We have working support for "long long int", use that */
269
270 #ifndef HAVE_INT64
271 typedef long long int int64;
272 #endif
273 #ifndef HAVE_UINT64
274 typedef unsigned long long int uint64;
275 #endif
276 #else                                                   /* not HAVE_LONG_INT_64 and not
277                                                                  * HAVE_LONG_LONG_INT_64 */
278
279 /* Won't actually work, but fall back to long int so that code compiles */
280 #ifndef HAVE_INT64
281 typedef long int int64;
282 #endif
283 #ifndef HAVE_UINT64
284 typedef unsigned long int uint64;
285 #endif
286
287 #define INT64_IS_BUSTED
288 #endif   /* not HAVE_LONG_INT_64 and not
289                                                                  * HAVE_LONG_LONG_INT_64 */
290
291 /* Decide if we need to decorate 64-bit constants */
292 #ifdef HAVE_LL_CONSTANTS
293 #define INT64CONST(x)  ((int64) x##LL)
294 #define UINT64CONST(x) ((uint64) x##ULL)
295 #else
296 #define INT64CONST(x)  ((int64) x)
297 #define UINT64CONST(x) ((uint64) x)
298 #endif
299
300
301 /* Select timestamp representation (float8 or int64) */
302 #if defined(USE_INTEGER_DATETIMES) && !defined(INT64_IS_BUSTED)
303 #define HAVE_INT64_TIMESTAMP
304 #endif
305
306 /* sig_atomic_t is required by ANSI C, but may be missing on old platforms */
307 #ifndef HAVE_SIG_ATOMIC_T
308 typedef int sig_atomic_t;
309 #endif
310
311 /*
312  * Size
313  *              Size of any memory resident object, as returned by sizeof.
314  */
315 typedef size_t Size;
316
317 /*
318  * Index
319  *              Index into any memory resident array.
320  *
321  * Note:
322  *              Indices are non negative.
323  */
324 typedef unsigned int Index;
325
326 /*
327  * Offset
328  *              Offset into any memory resident array.
329  *
330  * Note:
331  *              This differs from an Index in that an Index is always
332  *              non negative, whereas Offset may be negative.
333  */
334 typedef signed int Offset;
335
336 /*
337  * Common Postgres datatype names (as used in the catalogs)
338  */
339 typedef int16 int2;
340 typedef int32 int4;
341 typedef float float4;
342 typedef double float8;
343
344 /*
345  * Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId,
346  * CommandId
347  */
348
349 /* typedef Oid is in postgres_ext.h */
350
351 /*
352  * regproc is the type name used in the include/catalog headers, but
353  * RegProcedure is the preferred name in C code.
354  */
355 typedef Oid regproc;
356 typedef regproc RegProcedure;
357
358 typedef uint32 TransactionId;
359
360 typedef uint32 LocalTransactionId;
361
362 typedef uint32 SubTransactionId;
363
364 #define InvalidSubTransactionId         ((SubTransactionId) 0)
365 #define TopSubTransactionId                     ((SubTransactionId) 1)
366
367 /* MultiXactId must be equivalent to TransactionId, to fit in t_xmax */
368 typedef TransactionId MultiXactId;
369
370 typedef uint32 MultiXactOffset;
371
372 typedef uint32 CommandId;
373
374 #define FirstCommandId  ((CommandId) 0)
375
376 /*
377  * Array indexing support
378  */
379 #define MAXDIM 6
380 typedef struct
381 {
382         int                     indx[MAXDIM];
383 } IntArray;
384
385 /* ----------------
386  *              Variable-length datatypes all share the 'struct varlena' header.
387  *
388  * NOTE: for TOASTable types, this is an oversimplification, since the value
389  * may be compressed or moved out-of-line.      However datatype-specific routines
390  * are mostly content to deal with de-TOASTed values only, and of course
391  * client-side routines should never see a TOASTed value.  But even in a
392  * de-TOASTed value, beware of touching vl_len_ directly, as its representation
393  * is no longer convenient.  It's recommended that code always use the VARDATA,
394  * VARSIZE, and SET_VARSIZE macros instead of relying on direct mentions of
395  * the struct fields.  See postgres.h for details of the TOASTed form.
396  * ----------------
397  */
398 struct varlena
399 {
400         char            vl_len_[4];             /* Do not touch this field directly! */
401         char            vl_dat[1];
402 };
403
404 #define VARHDRSZ                ((int32) sizeof(int32))
405
406 /*
407  * These widely-used datatypes are just a varlena header and the data bytes.
408  * There is no terminating null or anything like that --- the data length is
409  * always VARSIZE(ptr) - VARHDRSZ.
410  */
411 typedef struct varlena bytea;
412 typedef struct varlena text;
413 typedef struct varlena BpChar;  /* blank-padded char, ie SQL char(n) */
414 typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */
415
416 /*
417  * Specialized array types.  These are physically laid out just the same
418  * as regular arrays (so that the regular array subscripting code works
419  * with them).  They exist as distinct types mostly for historical reasons:
420  * they have nonstandard I/O behavior which we don't want to change for fear
421  * of breaking applications that look at the system catalogs.  There is also
422  * an implementation issue for oidvector: it's part of the primary key for
423  * pg_proc, and we can't use the normal btree array support routines for that
424  * without circularity.
425  */
426 typedef struct
427 {
428         int32           vl_len_;                /* these fields must match ArrayType! */
429         int                     ndim;                   /* always 1 for int2vector */
430         int32           dataoffset;             /* always 0 for int2vector */
431         Oid                     elemtype;
432         int                     dim1;
433         int                     lbound1;
434         int2            values[1];              /* VARIABLE LENGTH ARRAY */
435 } int2vector;                                   /* VARIABLE LENGTH STRUCT */
436
437 typedef struct
438 {
439         int32           vl_len_;                /* these fields must match ArrayType! */
440         int                     ndim;                   /* always 1 for oidvector */
441         int32           dataoffset;             /* always 0 for oidvector */
442         Oid                     elemtype;
443         int                     dim1;
444         int                     lbound1;
445         Oid                     values[1];              /* VARIABLE LENGTH ARRAY */
446 } oidvector;                                    /* VARIABLE LENGTH STRUCT */
447
448 /*
449  * Representation of a Name: effectively just a C string, but null-padded to
450  * exactly NAMEDATALEN bytes.  The use of a struct is historical.
451  */
452 typedef struct nameData
453 {
454         char            data[NAMEDATALEN];
455 } NameData;
456 typedef NameData *Name;
457
458 #define NameStr(name)   ((name).data)
459
460 /*
461  * Support macros for escaping strings.  escape_backslash should be TRUE
462  * if generating a non-standard-conforming string.      Prefixing a string
463  * with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
464  * Beware of multiple evaluation of the "ch" argument!
465  */
466 #define SQL_STR_DOUBLE(ch, escape_backslash)    \
467         ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
468
469 #define ESCAPE_STRING_SYNTAX    'E'
470
471 /* ----------------------------------------------------------------
472  *                              Section 4:      IsValid macros for system types
473  * ----------------------------------------------------------------
474  */
475 /*
476  * BoolIsValid
477  *              True iff bool is valid.
478  */
479 #define BoolIsValid(boolean)    ((boolean) == false || (boolean) == true)
480
481 /*
482  * PointerIsValid
483  *              True iff pointer is valid.
484  */
485 #define PointerIsValid(pointer) ((void*)(pointer) != NULL)
486
487 /*
488  * PointerIsAligned
489  *              True iff pointer is properly aligned to point to the given type.
490  */
491 #define PointerIsAligned(pointer, type) \
492                 (((long)(pointer) % (sizeof (type))) == 0)
493
494 #define OidIsValid(objectId)  ((bool) ((objectId) != InvalidOid))
495
496 #define RegProcedureIsValid(p)  OidIsValid(p)
497
498
499 /* ----------------------------------------------------------------
500  *                              Section 5:      offsetof, lengthof, endof, alignment
501  * ----------------------------------------------------------------
502  */
503 /*
504  * offsetof
505  *              Offset of a structure/union field within that structure/union.
506  *
507  *              XXX This is supposed to be part of stddef.h, but isn't on
508  *              some systems (like SunOS 4).
509  */
510 #ifndef offsetof
511 #define offsetof(type, field)   ((long) &((type *)0)->field)
512 #endif   /* offsetof */
513
514 /*
515  * lengthof
516  *              Number of elements in an array.
517  */
518 #define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
519
520 /*
521  * endof
522  *              Address of the element one past the last in an array.
523  */
524 #define endof(array)    (&(array)[lengthof(array)])
525
526 /* ----------------
527  * Alignment macros: align a length or address appropriately for a given type.
528  * The fooALIGN() macros round up to a multiple of the required alignment,
529  * while the fooALIGN_DOWN() macros round down.  The latter are more useful
530  * for problems like "how many X-sized structures will fit in a page?".
531  *
532  * NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
533  * That case seems extremely unlikely to be needed in practice, however.
534  * ----------------
535  */
536
537 #define TYPEALIGN(ALIGNVAL,LEN)  \
538         (((long) (LEN) + ((ALIGNVAL) - 1)) & ~((long) ((ALIGNVAL) - 1)))
539
540 #define SHORTALIGN(LEN)                 TYPEALIGN(ALIGNOF_SHORT, (LEN))
541 #define INTALIGN(LEN)                   TYPEALIGN(ALIGNOF_INT, (LEN))
542 #define LONGALIGN(LEN)                  TYPEALIGN(ALIGNOF_LONG, (LEN))
543 #define DOUBLEALIGN(LEN)                TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
544 #define MAXALIGN(LEN)                   TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
545 /* MAXALIGN covers only built-in types, not buffers */
546 #define BUFFERALIGN(LEN)                TYPEALIGN(ALIGNOF_BUFFER, (LEN))
547
548 #define TYPEALIGN_DOWN(ALIGNVAL,LEN)  \
549         (((long) (LEN)) & ~((long) ((ALIGNVAL) - 1)))
550
551 #define SHORTALIGN_DOWN(LEN)    TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
552 #define INTALIGN_DOWN(LEN)              TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
553 #define LONGALIGN_DOWN(LEN)             TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
554 #define DOUBLEALIGN_DOWN(LEN)   TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
555 #define MAXALIGN_DOWN(LEN)              TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
556
557 /* ----------------------------------------------------------------
558  *                              Section 6:      widely useful macros
559  * ----------------------------------------------------------------
560  */
561 /*
562  * Max
563  *              Return the maximum of two numbers.
564  */
565 #define Max(x, y)               ((x) > (y) ? (x) : (y))
566
567 /*
568  * Min
569  *              Return the minimum of two numbers.
570  */
571 #define Min(x, y)               ((x) < (y) ? (x) : (y))
572
573 /*
574  * Abs
575  *              Return the absolute value of the argument.
576  */
577 #define Abs(x)                  ((x) >= 0 ? (x) : -(x))
578
579 /*
580  * StrNCpy
581  *      Like standard library function strncpy(), except that result string
582  *      is guaranteed to be null-terminated --- that is, at most N-1 bytes
583  *      of the source string will be kept.
584  *      Also, the macro returns no result (too hard to do that without
585  *      evaluating the arguments multiple times, which seems worse).
586  *
587  *      BTW: when you need to copy a non-null-terminated string (like a text
588  *      datum) and add a null, do not do it with StrNCpy(..., len+1).  That
589  *      might seem to work, but it fetches one byte more than there is in the
590  *      text object.  One fine day you'll have a SIGSEGV because there isn't
591  *      another byte before the end of memory.  Don't laugh, we've had real
592  *      live bug reports from real live users over exactly this mistake.
593  *      Do it honestly with "memcpy(dst,src,len); dst[len] = '\0';", instead.
594  */
595 #define StrNCpy(dst,src,len) \
596         do \
597         { \
598                 char * _dst = (dst); \
599                 Size _len = (len); \
600 \
601                 if (_len > 0) \
602                 { \
603                         strncpy(_dst, (src), _len); \
604                         _dst[_len-1] = '\0'; \
605                 } \
606         } while (0)
607
608
609 /* Get a bit mask of the bits set in non-long aligned addresses */
610 #define LONG_ALIGN_MASK (sizeof(long) - 1)
611
612 /*
613  * MemSet
614  *      Exactly the same as standard library function memset(), but considerably
615  *      faster for zeroing small word-aligned structures (such as parsetree nodes).
616  *      This has to be a macro because the main point is to avoid function-call
617  *      overhead.       However, we have also found that the loop is faster than
618  *      native libc memset() on some platforms, even those with assembler
619  *      memset() functions.  More research needs to be done, perhaps with
620  *      MEMSET_LOOP_LIMIT tests in configure.
621  */
622 #define MemSet(start, val, len) \
623         do \
624         { \
625                 /* must be void* because we don't know if it is integer aligned yet */ \
626                 void   *_vstart = (void *) (start); \
627                 int             _val = (val); \
628                 Size    _len = (len); \
629 \
630                 if ((((long) _vstart) & LONG_ALIGN_MASK) == 0 && \
631                         (_len & LONG_ALIGN_MASK) == 0 && \
632                         _val == 0 && \
633                         _len <= MEMSET_LOOP_LIMIT && \
634                         /* \
635                          *      If MEMSET_LOOP_LIMIT == 0, optimizer should find \
636                          *      the whole "if" false at compile time. \
637                          */ \
638                         MEMSET_LOOP_LIMIT != 0) \
639                 { \
640                         long *_start = (long *) _vstart; \
641                         long *_stop = (long *) ((char *) _start + _len); \
642                         while (_start < _stop) \
643                                 *_start++ = 0; \
644                 } \
645                 else \
646                         memset(_vstart, _val, _len); \
647         } while (0)
648
649 /*
650  * MemSetAligned is the same as MemSet except it omits the test to see if
651  * "start" is word-aligned.  This is okay to use if the caller knows a-priori
652  * that the pointer is suitably aligned (typically, because he just got it
653  * from palloc(), which always delivers a max-aligned pointer).
654  */
655 #define MemSetAligned(start, val, len) \
656         do \
657         { \
658                 long   *_start = (long *) (start); \
659                 int             _val = (val); \
660                 Size    _len = (len); \
661 \
662                 if ((_len & LONG_ALIGN_MASK) == 0 && \
663                         _val == 0 && \
664                         _len <= MEMSET_LOOP_LIMIT && \
665                         MEMSET_LOOP_LIMIT != 0) \
666                 { \
667                         long *_stop = (long *) ((char *) _start + _len); \
668                         while (_start < _stop) \
669                                 *_start++ = 0; \
670                 } \
671                 else \
672                         memset(_start, _val, _len); \
673         } while (0)
674
675
676 /*
677  * MemSetTest/MemSetLoop are a variant version that allow all the tests in
678  * MemSet to be done at compile time in cases where "val" and "len" are
679  * constants *and* we know the "start" pointer must be word-aligned.
680  * If MemSetTest succeeds, then it is okay to use MemSetLoop, otherwise use
681  * MemSetAligned.  Beware of multiple evaluations of the arguments when using
682  * this approach.
683  */
684 #define MemSetTest(val, len) \
685         ( ((len) & LONG_ALIGN_MASK) == 0 && \
686         (len) <= MEMSET_LOOP_LIMIT && \
687         MEMSET_LOOP_LIMIT != 0 && \
688         (val) == 0 )
689
690 #define MemSetLoop(start, val, len) \
691         do \
692         { \
693                 long * _start = (long *) (start); \
694                 long * _stop = (long *) ((char *) _start + (Size) (len)); \
695         \
696                 while (_start < _stop) \
697                         *_start++ = 0; \
698         } while (0)
699
700
701 /* ----------------------------------------------------------------
702  *                              Section 7:      random stuff
703  * ----------------------------------------------------------------
704  */
705
706 /* msb for char */
707 #define HIGHBIT                                 (0x80)
708 #define IS_HIGHBIT_SET(ch)              ((unsigned char)(ch) & HIGHBIT)
709
710 #define STATUS_OK                               (0)
711 #define STATUS_ERROR                    (-1)
712 #define STATUS_EOF                              (-2)
713 #define STATUS_FOUND                    (1)
714 #define STATUS_WAITING                  (2)
715
716
717 /* ----------------------------------------------------------------
718  *                              Section 8: system-specific hacks
719  *
720  *              This should be limited to things that absolutely have to be
721  *              included in every source file.  The port-specific header file
722  *              is usually a better place for this sort of thing.
723  * ----------------------------------------------------------------
724  */
725
726 /*
727  *      NOTE:  this is also used for opening text files.
728  *      WIN32 treats Control-Z as EOF in files opened in text mode.
729  *      Therefore, we open files in binary mode on Win32 so we can read
730  *      literal control-Z.      The other affect is that we see CRLF, but
731  *      that is OK because we can already handle those cleanly.
732  */
733 #if defined(WIN32) || defined(__CYGWIN__)
734 #define PG_BINARY       O_BINARY
735 #define PG_BINARY_A "ab"
736 #define PG_BINARY_R "rb"
737 #define PG_BINARY_W "wb"
738 #else
739 #define PG_BINARY       0
740 #define PG_BINARY_A "a"
741 #define PG_BINARY_R "r"
742 #define PG_BINARY_W "w"
743 #endif
744
745 #if defined(sun) && defined(__sparc__) && !defined(__SVR4)
746 #include <unistd.h>
747 #endif
748
749 /* These are for things that are one way on Unix and another on NT */
750 #define NULL_DEV                "/dev/null"
751
752 /*
753  * Provide prototypes for routines not present in a particular machine's
754  * standard C library.
755  */
756
757 #if !HAVE_DECL_SNPRINTF
758 extern int
759 snprintf(char *str, size_t count, const char *fmt,...)
760 /* This extension allows gcc to check the format string */
761 __attribute__((format(printf, 3, 4)));
762 #endif
763
764 #if !HAVE_DECL_VSNPRINTF
765 extern int      vsnprintf(char *str, size_t count, const char *fmt, va_list args);
766 #endif
767
768 #if !defined(HAVE_MEMMOVE) && !defined(memmove)
769 #define memmove(d, s, c)                bcopy(s, d, c)
770 #endif
771
772 #ifndef PGDLLIMPORT
773 #define PGDLLIMPORT                             /* no special DLL markers on most ports */
774 #endif
775
776 /*
777  * The following is used as the arg list for signal handlers.  Any ports
778  * that take something other than an int argument should override this in
779  * their pg_config_os.h file.  Note that variable names are required
780  * because it is used in both the prototypes as well as the definitions.
781  * Note also the long name.  We expect that this won't collide with
782  * other names causing compiler warnings.
783  */
784
785 #ifndef SIGNAL_ARGS
786 #define SIGNAL_ARGS  int postgres_signal_arg
787 #endif
788
789 /*
790  * When there is no sigsetjmp, its functionality is provided by plain
791  * setjmp. Incidentally, nothing provides setjmp's functionality in
792  * that case.
793  */
794 #ifndef HAVE_SIGSETJMP
795 #define sigjmp_buf jmp_buf
796 #define sigsetjmp(x,y) setjmp(x)
797 #define siglongjmp longjmp
798 #endif
799
800 #if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
801 extern int      fdatasync(int fildes);
802 #endif
803
804 /* If strtoq() exists, rename it to the more standard strtoll() */
805 #if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOLL) && defined(HAVE_STRTOQ)
806 #define strtoll strtoq
807 #define HAVE_STRTOLL 1
808 #endif
809
810 /* If strtouq() exists, rename it to the more standard strtoull() */
811 #if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOULL) && defined(HAVE_STRTOUQ)
812 #define strtoull strtouq
813 #define HAVE_STRTOULL 1
814 #endif
815
816 /*
817  * We assume if we have these two functions, we have their friends too, and
818  * can use the wide-character functions.
819  */
820 #if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
821 #define USE_WIDE_UPPER_LOWER
822 #endif
823    
824 /* EXEC_BACKEND defines */
825 #ifdef EXEC_BACKEND
826 #define NON_EXEC_STATIC
827 #else
828 #define NON_EXEC_STATIC static
829 #endif
830
831 /* /port compatibility functions */
832 #include "port.h"
833
834 #endif   /* C_H */