]> granicus.if.org Git - postgresql/blob - src/include/c.h
Make pg_regress accept a command-line option for the temporary installation's
[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.187 2005/07/02 17:01:52 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 port file */
88 #endif
89 #endif
90
91 /* Must be before gettext() games below */
92 #include <locale.h>
93
94 #define _(x) gettext((x))
95
96 #ifdef ENABLE_NLS
97 #include <libintl.h>
98 #else
99 #define gettext(x) (x)
100 #endif
101
102 /*
103  *      These strings are to be translation via xgettext.  We can't
104  *      call gettext() because it is located in variable initialization and
105  *      a function call can not be used.
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
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 /* BeOS defines bool already, but the compiler chokes on the
175  * #ifndef unless we wrap it in this check.
176  */
177 #ifndef __BEOS__
178
179 #ifndef __cplusplus
180
181 #ifndef bool
182 typedef char bool;
183 #endif
184
185 #ifndef true
186 #define true    ((bool) 1)
187 #endif
188
189 #ifndef false
190 #define false   ((bool) 0)
191 #endif
192 #endif   /* not C++ */
193 #endif   /* __BEOS__ */
194
195 typedef bool *BoolPtr;
196
197 #ifndef TRUE
198 #define TRUE    1
199 #endif
200
201 #ifndef FALSE
202 #define FALSE   0
203 #endif
204
205 /*
206  * NULL
207  *              Null pointer.
208  */
209 #ifndef NULL
210 #define NULL    ((void *) 0)
211 #endif
212
213
214 /* ----------------------------------------------------------------
215  *                              Section 3:      standard system types
216  * ----------------------------------------------------------------
217  */
218
219 /*
220  * Pointer
221  *              Variable holding address of any memory resident object.
222  *
223  *              XXX Pointer arithmetic is done with this, so it can't be void *
224  *              under "true" ANSI compilers.
225  */
226 typedef char *Pointer;
227
228 /*
229  * intN
230  *              Signed integer, EXACTLY N BITS IN SIZE,
231  *              used for numerical computations and the
232  *              frontend/backend protocol.
233  */
234 #ifndef HAVE_INT8
235 typedef signed char int8;               /* == 8 bits */
236 typedef signed short int16;             /* == 16 bits */
237 typedef signed int int32;               /* == 32 bits */
238 #endif   /* not HAVE_INT8 */
239
240 /*
241  * uintN
242  *              Unsigned integer, EXACTLY N BITS IN SIZE,
243  *              used for numerical computations and the
244  *              frontend/backend protocol.
245  */
246 #ifndef HAVE_UINT8
247 typedef unsigned char uint8;    /* == 8 bits */
248 typedef unsigned short uint16;  /* == 16 bits */
249 typedef unsigned int uint32;    /* == 32 bits */
250 #endif   /* not HAVE_UINT8 */
251
252 /*
253  * bitsN
254  *              Unit of bitwise operation, AT LEAST N BITS IN SIZE.
255  */
256 typedef uint8 bits8;                    /* >= 8 bits */
257 typedef uint16 bits16;                  /* >= 16 bits */
258 typedef uint32 bits32;                  /* >= 32 bits */
259
260 /*
261  * floatN
262  *              Floating point number, AT LEAST N BITS IN SIZE,
263  *              used for numerical computations.
264  *
265  *              Since sizeof(floatN) may be > sizeof(char *), always pass
266  *              floatN by reference.
267  *
268  * XXX: these typedefs are now deprecated in favor of float4 and float8.
269  * They will eventually go away.
270  */
271 typedef float float32data;
272 typedef double float64data;
273 typedef float *float32;
274 typedef double *float64;
275
276 /*
277  * 64-bit integers
278  */
279 #ifdef HAVE_LONG_INT_64
280 /* Plain "long int" fits, use it */
281
282 #ifndef HAVE_INT64
283 typedef long int int64;
284 #endif
285 #ifndef HAVE_UINT64
286 typedef unsigned long int uint64;
287 #endif
288
289 #elif defined(HAVE_LONG_LONG_INT_64)
290 /* We have working support for "long long int", use that */
291
292 #ifndef HAVE_INT64
293 typedef long long int int64;
294 #endif
295 #ifndef HAVE_UINT64
296 typedef unsigned long long int uint64;
297 #endif
298
299 #else                                                   /* not HAVE_LONG_INT_64 and not
300                                                                  * HAVE_LONG_LONG_INT_64 */
301
302 /* Won't actually work, but fall back to long int so that code compiles */
303 #ifndef HAVE_INT64
304 typedef long int int64;
305 #endif
306 #ifndef HAVE_UINT64
307 typedef unsigned long int uint64;
308 #endif
309
310 #define INT64_IS_BUSTED
311 #endif   /* not HAVE_LONG_INT_64 and not
312                                                                  * HAVE_LONG_LONG_INT_64 */
313
314 /* Decide if we need to decorate 64-bit constants */
315 #ifdef HAVE_LL_CONSTANTS
316 #define INT64CONST(x)  ((int64) x##LL)
317 #define UINT64CONST(x) ((uint64) x##ULL)
318 #else
319 #define INT64CONST(x)  ((int64) x)
320 #define UINT64CONST(x) ((uint64) x)
321 #endif
322
323
324 /* Select timestamp representation (float8 or int64) */
325 #if defined(USE_INTEGER_DATETIMES) && !defined(INT64_IS_BUSTED)
326 #define HAVE_INT64_TIMESTAMP
327 #endif
328
329 /* sig_atomic_t is required by ANSI C, but may be missing on old platforms */
330 #ifndef HAVE_SIG_ATOMIC_T
331 typedef int sig_atomic_t;
332 #endif
333
334 /*
335  * Size
336  *              Size of any memory resident object, as returned by sizeof.
337  */
338 typedef size_t Size;
339
340 /*
341  * Index
342  *              Index into any memory resident array.
343  *
344  * Note:
345  *              Indices are non negative.
346  */
347 typedef unsigned int Index;
348
349 /*
350  * Offset
351  *              Offset into any memory resident array.
352  *
353  * Note:
354  *              This differs from an Index in that an Index is always
355  *              non negative, whereas Offset may be negative.
356  */
357 typedef signed int Offset;
358
359 /*
360  * Common Postgres datatype names (as used in the catalogs)
361  */
362 typedef int16 int2;
363 typedef int32 int4;
364 typedef float float4;
365 typedef double float8;
366
367 /*
368  * Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId,
369  * CommandId
370  */
371
372 /* typedef Oid is in postgres_ext.h */
373
374 /*
375  * regproc is the type name used in the include/catalog headers, but
376  * RegProcedure is the preferred name in C code.
377  */
378 typedef Oid regproc;
379 typedef regproc RegProcedure;
380
381 typedef uint32 TransactionId;
382
383 typedef uint32 SubTransactionId;
384
385 #define InvalidSubTransactionId         ((SubTransactionId) 0)
386 #define TopSubTransactionId                     ((SubTransactionId) 1)
387
388 /* MultiXactId must be equivalent to TransactionId, to fit in t_xmax */
389 typedef TransactionId MultiXactId;
390
391 typedef uint32 MultiXactOffset;
392
393 typedef uint32 CommandId;
394
395 #define FirstCommandId  ((CommandId) 0)
396
397 /*
398  * Array indexing support
399  */
400 #define MAXDIM 6
401 typedef struct
402 {
403         int                     indx[MAXDIM];
404 } IntArray;
405
406 /* ----------------
407  *              Variable-length datatypes all share the 'struct varlena' header.
408  *
409  * NOTE: for TOASTable types, this is an oversimplification, since the value
410  * may be compressed or moved out-of-line.      However datatype-specific routines
411  * are mostly content to deal with de-TOASTed values only, and of course
412  * client-side routines should never see a TOASTed value.  See postgres.h for
413  * details of the TOASTed form.
414  * ----------------
415  */
416 struct varlena
417 {
418         int32           vl_len;
419         char            vl_dat[1];
420 };
421
422 #define VARHDRSZ                ((int32) sizeof(int32))
423
424 /*
425  * These widely-used datatypes are just a varlena header and the data bytes.
426  * There is no terminating null or anything like that --- the data length is
427  * always VARSIZE(ptr) - VARHDRSZ.
428  */
429 typedef struct varlena bytea;
430 typedef struct varlena text;
431 typedef struct varlena BpChar;  /* blank-padded char, ie SQL char(n) */
432 typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */
433
434 /*
435  * Specialized array types.  These are physically laid out just the same
436  * as regular arrays (so that the regular array subscripting code works
437  * with them).  They exist as distinct types mostly for historical reasons:
438  * they have nonstandard I/O behavior which we don't want to change for fear
439  * of breaking applications that look at the system catalogs.  There is also
440  * an implementation issue for oidvector: it's part of the primary key for
441  * pg_proc, and we can't use the normal btree array support routines for that
442  * without circularity.
443  */
444 typedef struct
445 {
446         int32           size;                   /* these fields must match ArrayType! */
447         int                     ndim;
448         int                     flags;
449         Oid                     elemtype;
450         int                     dim1;
451         int                     lbound1;
452         int2            values[1];              /* VARIABLE LENGTH ARRAY */
453 } int2vector;                                   /* VARIABLE LENGTH STRUCT */
454
455 typedef struct
456 {
457         int32           size;                   /* these fields must match ArrayType! */
458         int                     ndim;
459         int                     flags;
460         Oid                     elemtype;
461         int                     dim1;
462         int                     lbound1;
463         Oid                     values[1];              /* VARIABLE LENGTH ARRAY */
464 } oidvector;                                    /* VARIABLE LENGTH STRUCT */
465
466 /*
467  * We want NameData to have length NAMEDATALEN and int alignment,
468  * because that's how the data type 'name' is defined in pg_type.
469  * Use a union to make sure the compiler agrees.  Note that NAMEDATALEN
470  * must be a multiple of sizeof(int), else sizeof(NameData) will probably
471  * not come out equal to NAMEDATALEN.
472  */
473 typedef union nameData
474 {
475         char            data[NAMEDATALEN];
476         int                     alignmentDummy;
477 } NameData;
478 typedef NameData *Name;
479
480 #define NameStr(name)   ((name).data)
481
482 #define SQL_STR_DOUBLE(ch)      ((ch) == '\'' || (ch) == '\\')
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-int32 aligned addresses */
616 #define INT_ALIGN_MASK (sizeof(int32) - 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  *      platform-specific MEMSET_LOOP_LIMIT values or tests in configure.
627  *
628  *      bjm 2002-10-08
629  */
630 #define MemSet(start, val, len) \
631         do \
632         { \
633                 int32  *_start = (int32 *) (start); \
634                 int             _val = (val); \
635                 Size    _len = (len); \
636 \
637                 if ((((long) _start) & INT_ALIGN_MASK) == 0 && \
638                         (_len & INT_ALIGN_MASK) == 0 && \
639                         _val == 0 && \
640                         _len <= MEMSET_LOOP_LIMIT) \
641                 { \
642                         int32 *_stop = (int32 *) ((char *) _start + _len); \
643                         while (_start < _stop) \
644                                 *_start++ = 0; \
645                 } \
646                 else \
647                         memset(_start, _val, _len); \
648         } while (0)
649
650 #define MEMSET_LOOP_LIMIT  1024
651
652 /*
653  * MemSetAligned is the same as MemSet except it omits the test to see if
654  * "start" is word-aligned.  This is okay to use if the caller knows a-priori
655  * that the pointer is suitably aligned (typically, because he just got it
656  * from palloc(), which always delivers a max-aligned pointer).
657  */
658 #define MemSetAligned(start, val, len) \
659         do \
660         { \
661                 int32  *_start = (int32 *) (start); \
662                 int             _val = (val); \
663                 Size    _len = (len); \
664 \
665                 if ((_len & INT_ALIGN_MASK) == 0 && \
666                         _val == 0 && \
667                         _len <= MEMSET_LOOP_LIMIT) \
668                 { \
669                         int32 *_stop = (int32 *) ((char *) _start + _len); \
670                         while (_start < _stop) \
671                                 *_start++ = 0; \
672                 } \
673                 else \
674                         memset(_start, _val, _len); \
675         } while (0)
676
677
678 /*
679  * MemSetTest/MemSetLoop are a variant version that allow all the tests in
680  * MemSet to be done at compile time in cases where "val" and "len" are
681  * constants *and* we know the "start" pointer must be word-aligned.
682  * If MemSetTest succeeds, then it is okay to use MemSetLoop, otherwise use
683  * MemSetAligned.  Beware of multiple evaluations of the arguments when using
684  * this approach.
685  */
686 #define MemSetTest(val, len) \
687         ( ((len) & INT_ALIGN_MASK) == 0 && \
688         (len) <= MEMSET_LOOP_LIMIT && \
689         (val) == 0 )
690
691 #define MemSetLoop(start, val, len) \
692         do \
693         { \
694                 int32 * _start = (int32 *) (start); \
695                 int32 * _stop = (int32 *) ((char *) _start + (Size) (len)); \
696         \
697                 while (_start < _stop) \
698                         *_start++ = 0; \
699         } while (0)
700
701
702 /* ----------------------------------------------------------------
703  *                              Section 7:      random stuff
704  * ----------------------------------------------------------------
705  */
706
707 /* msb for char */
708 #define CSIGNBIT (0x80)
709
710 #define STATUS_OK                               (0)
711 #define STATUS_ERROR                    (-1)
712 #define STATUS_EOF                              (-2)
713 #define STATUS_FOUND                    (1)
714
715
716 /* ----------------------------------------------------------------
717  *                              Section 8: system-specific hacks
718  *
719  *              This should be limited to things that absolutely have to be
720  *              included in every source file.  The port-specific header file
721  *              is usually a better place for this sort of thing.
722  * ----------------------------------------------------------------
723  */
724
725 /*
726  *      NOTE:  this is also used for opening text files.
727  *      WIN32 treats Control-Z as EOF in files opened in text mode.
728  *      Therefore, we open files in binary mode on Win32 so we can read
729  *      literal control-Z.      The other affect is that we see CRLF, but
730  *      that is OK because we can already handle those cleanly.
731  */
732 #if defined(WIN32) || defined(__CYGWIN__)
733 #define PG_BINARY       O_BINARY
734 #define PG_BINARY_R "rb"
735 #define PG_BINARY_W "wb"
736 #else
737 #define PG_BINARY       0
738 #define PG_BINARY_R "r"
739 #define PG_BINARY_W "w"
740 #endif
741
742 #if defined(sun) && defined(__sparc__) && !defined(__SVR4)
743 #include <unistd.h>
744 #endif
745
746 /* These are for things that are one way on Unix and another on NT */
747 #define NULL_DEV                "/dev/null"
748
749 /*
750  * Provide prototypes for routines not present in a particular machine's
751  * standard C library.
752  */
753
754 #if !HAVE_DECL_SNPRINTF
755 extern int
756 snprintf(char *str, size_t count, const char *fmt,...)
757 /* This extension allows gcc to check the format string */
758 __attribute__((format(printf, 3, 4)));
759 #endif
760
761 #if !HAVE_DECL_VSNPRINTF
762 extern int      vsnprintf(char *str, size_t count, const char *fmt, va_list args);
763 #endif
764
765 #if !defined(HAVE_MEMMOVE) && !defined(memmove)
766 #define memmove(d, s, c)                bcopy(s, d, c)
767 #endif
768
769 #ifndef DLLIMPORT
770 #define DLLIMPORT                               /* no special DLL markers on most ports */
771 #endif
772
773 /*
774  * The following is used as the arg list for signal handlers.  Any ports
775  * that take something other than an int argument should override this in
776  * their pg_config_os.h file.  Note that variable names are required
777  * because it is used in both the prototypes as well as the definitions.
778  * Note also the long name.  We expect that this won't collide with
779  * other names causing compiler warnings.
780  */
781
782 #ifndef SIGNAL_ARGS
783 #define SIGNAL_ARGS  int postgres_signal_arg
784 #endif
785
786 /*
787  * When there is no sigsetjmp, its functionality is provided by plain
788  * setjmp. Incidentally, nothing provides setjmp's functionality in
789  * that case.
790  */
791 #ifndef HAVE_SIGSETJMP
792 #define sigjmp_buf jmp_buf
793 #define sigsetjmp(x,y) setjmp(x)
794 #define siglongjmp longjmp
795 #endif
796
797 #if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
798 extern int      fdatasync(int fildes);
799 #endif
800
801 /* If strtoq() exists, rename it to the more standard strtoll() */
802 #if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOLL) && defined(HAVE_STRTOQ)
803 #define strtoll strtoq
804 #define HAVE_STRTOLL 1
805 #endif
806
807 /* If strtouq() exists, rename it to the more standard strtoull() */
808 #if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOULL) && defined(HAVE_STRTOUQ)
809 #define strtoull strtouq
810 #define HAVE_STRTOULL 1
811 #endif
812
813 /* EXEC_BACKEND defines */
814 #ifdef EXEC_BACKEND
815 #define NON_EXEC_STATIC
816 #else
817 #define NON_EXEC_STATIC static
818 #endif
819
820 /* /port compatibility functions */
821 #include "port.h"
822
823 #endif   /* C_H */