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