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