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