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