1 /*-------------------------------------------------------------------------
4 * Fundamental C definitions. This is included by every .c file in
5 * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate).
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...
12 * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
13 * Portions Copyright (c) 1994, Regents of the University of California
17 *-------------------------------------------------------------------------
20 *----------------------------------------------------------------
23 * When adding stuff to this file, please try to put stuff
24 * into the relevant section, or add new sections as appropriate.
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
36 * 8) system-specific hacks
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.
42 *----------------------------------------------------------------
47 #include "postgres_ext.h"
49 /* Must undef pg_config_ext.h symbols before including pg_config.h */
52 #include "pg_config.h"
53 #include "pg_config_manual.h" /* must be after pg_config.h */
55 #if !defined(WIN32) && !defined(__CYGWIN__) /* win32 includes further down */
56 #include "pg_config_os.h" /* must be before any system header files */
59 #if _MSC_VER >= 1400 || defined(HAVE_CRTDEFS_H)
60 #define errcode __msvc_errcode
66 * We have to include stdlib.h here because it defines many of these macros
67 * on some platforms, and we only want our definitions used if stdlib.h doesn't
68 * have its own. The same goes for stddef and stdarg if present.
82 #include <sys/types.h>
85 #if defined(WIN32) || defined(__CYGWIN__)
86 #include <fcntl.h> /* ensure O_BINARY is available */
89 #if defined(WIN32) || defined(__CYGWIN__)
90 /* We have to redefine some system functions after they are included above. */
91 #include "pg_config_os.h"
94 /* Must be before gettext() games below */
97 #define _(x) gettext(x)
102 #define gettext(x) (x)
103 #define dgettext(d,x) (x)
104 #define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
105 #define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
109 * Use this to mark string constants as needing translation at some later
110 * time, rather than immediately. This is useful for cases where you need
111 * access to the original string and translated string, and for cases where
112 * immediate translation is not possible, like when initializing global
114 * http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html
116 #define gettext_noop(x) (x)
119 /* ----------------------------------------------------------------
120 * Section 1: hacks to cope with non-ANSI C compilers
122 * type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
123 * ----------------------------------------------------------------
128 * Convert the argument to a string, using the C preprocessor.
130 * Concatenate two arguments together, using the C preprocessor.
132 * Note: the standard Autoconf macro AC_C_STRINGIZE actually only checks
133 * whether #identifier works, but if we have that we likely have ## too.
135 #if defined(HAVE_STRINGIZE)
137 #define CppAsString(identifier) #identifier
138 #define CppConcat(x, y) x##y
139 #else /* !HAVE_STRINGIZE */
141 #define CppAsString(identifier) "identifier"
144 * CppIdentity -- On Reiser based cpp's this is used to concatenate
145 * two tokens. That is
146 * CppIdentity(A)B ==> AB
147 * We renamed it to _private_CppIdentity because it should not
148 * be referenced outside this file. On other cpp's it
151 #define _priv_CppIdentity(x)x
152 #define CppConcat(x, y) _priv_CppIdentity(x)y
153 #endif /* !HAVE_STRINGIZE */
156 * dummyret is used to set return values in macros that use ?: to make
157 * assignments. gcc wants these to be void, other compilers like char
159 #ifdef __GNUC__ /* GNU cc */
160 #define dummyret void
162 #define dummyret char
166 #define __attribute__(_arg_)
169 /* ----------------------------------------------------------------
170 * Section 2: bool, true, false, TRUE, FALSE, NULL
171 * ----------------------------------------------------------------
176 * Boolean value, either true or false.
178 * XXX for C++ compilers, we assume the compiler has a compatible
179 * built-in definition of bool.
189 #define true ((bool) 1)
193 #define false ((bool) 0)
197 typedef bool *BoolPtr;
212 #define NULL ((void *) 0)
216 /* ----------------------------------------------------------------
217 * Section 3: standard system types
218 * ----------------------------------------------------------------
223 * Variable holding address of any memory resident object.
225 * XXX Pointer arithmetic is done with this, so it can't be void *
226 * under "true" ANSI compilers.
228 typedef char *Pointer;
232 * Signed integer, EXACTLY N BITS IN SIZE,
233 * used for numerical computations and the
234 * frontend/backend protocol.
237 typedef signed char int8; /* == 8 bits */
238 typedef signed short int16; /* == 16 bits */
239 typedef signed int int32; /* == 32 bits */
240 #endif /* not HAVE_INT8 */
244 * Unsigned integer, EXACTLY N BITS IN SIZE,
245 * used for numerical computations and the
246 * frontend/backend protocol.
249 typedef unsigned char uint8; /* == 8 bits */
250 typedef unsigned short uint16; /* == 16 bits */
251 typedef unsigned int uint32; /* == 32 bits */
252 #endif /* not HAVE_UINT8 */
256 * Unit of bitwise operation, AT LEAST N BITS IN SIZE.
258 typedef uint8 bits8; /* >= 8 bits */
259 typedef uint16 bits16; /* >= 16 bits */
260 typedef uint32 bits32; /* >= 32 bits */
265 #ifdef HAVE_LONG_INT_64
266 /* Plain "long int" fits, use it */
269 typedef long int int64;
272 typedef unsigned long int uint64;
274 #elif defined(HAVE_LONG_LONG_INT_64)
275 /* We have working support for "long long int", use that */
278 typedef long long int int64;
281 typedef unsigned long long int uint64;
284 /* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
285 #error must have a working 64-bit integer datatype
288 /* Decide if we need to decorate 64-bit constants */
289 #ifdef HAVE_LL_CONSTANTS
290 #define INT64CONST(x) ((int64) x##LL)
291 #define UINT64CONST(x) ((uint64) x##ULL)
293 #define INT64CONST(x) ((int64) x)
294 #define UINT64CONST(x) ((uint64) x)
298 /* Select timestamp representation (float8 or int64) */
299 #ifdef USE_INTEGER_DATETIMES
300 #define HAVE_INT64_TIMESTAMP
303 /* sig_atomic_t is required by ANSI C, but may be missing on old platforms */
304 #ifndef HAVE_SIG_ATOMIC_T
305 typedef int sig_atomic_t;
310 * Size of any memory resident object, as returned by sizeof.
316 * Index into any memory resident array.
319 * Indices are non negative.
321 typedef unsigned int Index;
325 * Offset into any memory resident array.
328 * This differs from an Index in that an Index is always
329 * non negative, whereas Offset may be negative.
331 typedef signed int Offset;
334 * Common Postgres datatype names (as used in the catalogs)
336 typedef float float4;
337 typedef double float8;
340 * Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId,
344 /* typedef Oid is in postgres_ext.h */
347 * regproc is the type name used in the include/catalog headers, but
348 * RegProcedure is the preferred name in C code.
351 typedef regproc RegProcedure;
353 typedef uint32 TransactionId;
355 typedef uint32 LocalTransactionId;
357 typedef uint32 SubTransactionId;
359 #define InvalidSubTransactionId ((SubTransactionId) 0)
360 #define TopSubTransactionId ((SubTransactionId) 1)
362 /* MultiXactId must be equivalent to TransactionId, to fit in t_xmax */
363 typedef TransactionId MultiXactId;
365 typedef uint32 MultiXactOffset;
367 typedef uint32 CommandId;
369 #define FirstCommandId ((CommandId) 0)
372 * Array indexing support
381 * Variable-length datatypes all share the 'struct varlena' header.
383 * NOTE: for TOASTable types, this is an oversimplification, since the value
384 * may be compressed or moved out-of-line. However datatype-specific routines
385 * are mostly content to deal with de-TOASTed values only, and of course
386 * client-side routines should never see a TOASTed value. But even in a
387 * de-TOASTed value, beware of touching vl_len_ directly, as its representation
388 * is no longer convenient. It's recommended that code always use the VARDATA,
389 * VARSIZE, and SET_VARSIZE macros instead of relying on direct mentions of
390 * the struct fields. See postgres.h for details of the TOASTed form.
395 char vl_len_[4]; /* Do not touch this field directly! */
399 #define VARHDRSZ ((int32) sizeof(int32))
402 * These widely-used datatypes are just a varlena header and the data bytes.
403 * There is no terminating null or anything like that --- the data length is
404 * always VARSIZE(ptr) - VARHDRSZ.
406 typedef struct varlena bytea;
407 typedef struct varlena text;
408 typedef struct varlena BpChar; /* blank-padded char, ie SQL char(n) */
409 typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */
412 * Specialized array types. These are physically laid out just the same
413 * as regular arrays (so that the regular array subscripting code works
414 * with them). They exist as distinct types mostly for historical reasons:
415 * they have nonstandard I/O behavior which we don't want to change for fear
416 * of breaking applications that look at the system catalogs. There is also
417 * an implementation issue for oidvector: it's part of the primary key for
418 * pg_proc, and we can't use the normal btree array support routines for that
419 * without circularity.
423 int32 vl_len_; /* these fields must match ArrayType! */
424 int ndim; /* always 1 for int2vector */
425 int32 dataoffset; /* always 0 for int2vector */
429 int16 values[1]; /* VARIABLE LENGTH ARRAY */
430 } int2vector; /* VARIABLE LENGTH STRUCT */
434 int32 vl_len_; /* these fields must match ArrayType! */
435 int ndim; /* always 1 for oidvector */
436 int32 dataoffset; /* always 0 for oidvector */
440 Oid values[1]; /* VARIABLE LENGTH ARRAY */
441 } oidvector; /* VARIABLE LENGTH STRUCT */
444 * Representation of a Name: effectively just a C string, but null-padded to
445 * exactly NAMEDATALEN bytes. The use of a struct is historical.
447 typedef struct nameData
449 char data[NAMEDATALEN];
451 typedef NameData *Name;
453 #define NameStr(name) ((name).data)
456 * Support macros for escaping strings. escape_backslash should be TRUE
457 * if generating a non-standard-conforming string. Prefixing a string
458 * with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
459 * Beware of multiple evaluation of the "ch" argument!
461 #define SQL_STR_DOUBLE(ch, escape_backslash) \
462 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
464 #define ESCAPE_STRING_SYNTAX 'E'
466 /* ----------------------------------------------------------------
467 * Section 4: IsValid macros for system types
468 * ----------------------------------------------------------------
472 * True iff bool is valid.
474 #define BoolIsValid(boolean) ((boolean) == false || (boolean) == true)
478 * True iff pointer is valid.
480 #define PointerIsValid(pointer) ((const void*)(pointer) != NULL)
484 * True iff pointer is properly aligned to point to the given type.
486 #define PointerIsAligned(pointer, type) \
487 (((intptr_t)(pointer) % (sizeof (type))) == 0)
489 #define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
491 #define RegProcedureIsValid(p) OidIsValid(p)
494 /* ----------------------------------------------------------------
495 * Section 5: offsetof, lengthof, endof, alignment
496 * ----------------------------------------------------------------
500 * Offset of a structure/union field within that structure/union.
502 * XXX This is supposed to be part of stddef.h, but isn't on
503 * some systems (like SunOS 4).
506 #define offsetof(type, field) ((long) &((type *)0)->field)
507 #endif /* offsetof */
511 * Number of elements in an array.
513 #define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
517 * Address of the element one past the last in an array.
519 #define endof(array) (&(array)[lengthof(array)])
522 * Alignment macros: align a length or address appropriately for a given type.
523 * The fooALIGN() macros round up to a multiple of the required alignment,
524 * while the fooALIGN_DOWN() macros round down. The latter are more useful
525 * for problems like "how many X-sized structures will fit in a page?".
527 * NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
528 * That case seems extremely unlikely to be needed in practice, however.
532 #define TYPEALIGN(ALIGNVAL,LEN) \
533 (((intptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((intptr_t) ((ALIGNVAL) - 1)))
535 #define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
536 #define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
537 #define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
538 #define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
539 #define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
540 /* MAXALIGN covers only built-in types, not buffers */
541 #define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN))
543 #define TYPEALIGN_DOWN(ALIGNVAL,LEN) \
544 (((intptr_t) (LEN)) & ~((intptr_t) ((ALIGNVAL) - 1)))
546 #define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
547 #define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
548 #define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
549 #define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
550 #define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
552 /* ----------------------------------------------------------------
553 * Section 6: widely useful macros
554 * ----------------------------------------------------------------
558 * Return the maximum of two numbers.
560 #define Max(x, y) ((x) > (y) ? (x) : (y))
564 * Return the minimum of two numbers.
566 #define Min(x, y) ((x) < (y) ? (x) : (y))
570 * Return the absolute value of the argument.
572 #define Abs(x) ((x) >= 0 ? (x) : -(x))
576 * Like standard library function strncpy(), except that result string
577 * is guaranteed to be null-terminated --- that is, at most N-1 bytes
578 * of the source string will be kept.
579 * Also, the macro returns no result (too hard to do that without
580 * evaluating the arguments multiple times, which seems worse).
582 * BTW: when you need to copy a non-null-terminated string (like a text
583 * datum) and add a null, do not do it with StrNCpy(..., len+1). That
584 * might seem to work, but it fetches one byte more than there is in the
585 * text object. One fine day you'll have a SIGSEGV because there isn't
586 * another byte before the end of memory. Don't laugh, we've had real
587 * live bug reports from real live users over exactly this mistake.
588 * Do it honestly with "memcpy(dst,src,len); dst[len] = '\0';", instead.
590 #define StrNCpy(dst,src,len) \
593 char * _dst = (dst); \
598 strncpy(_dst, (src), _len); \
599 _dst[_len-1] = '\0'; \
604 /* Get a bit mask of the bits set in non-long aligned addresses */
605 #define LONG_ALIGN_MASK (sizeof(long) - 1)
609 * Exactly the same as standard library function memset(), but considerably
610 * faster for zeroing small word-aligned structures (such as parsetree nodes).
611 * This has to be a macro because the main point is to avoid function-call
612 * overhead. However, we have also found that the loop is faster than
613 * native libc memset() on some platforms, even those with assembler
614 * memset() functions. More research needs to be done, perhaps with
615 * MEMSET_LOOP_LIMIT tests in configure.
617 #define MemSet(start, val, len) \
620 /* must be void* because we don't know if it is integer aligned yet */ \
621 void *_vstart = (void *) (start); \
625 if ((((intptr_t) _vstart) & LONG_ALIGN_MASK) == 0 && \
626 (_len & LONG_ALIGN_MASK) == 0 && \
628 _len <= MEMSET_LOOP_LIMIT && \
630 * If MEMSET_LOOP_LIMIT == 0, optimizer should find \
631 * the whole "if" false at compile time. \
633 MEMSET_LOOP_LIMIT != 0) \
635 long *_start = (long *) _vstart; \
636 long *_stop = (long *) ((char *) _start + _len); \
637 while (_start < _stop) \
641 memset(_vstart, _val, _len); \
645 * MemSetAligned is the same as MemSet except it omits the test to see if
646 * "start" is word-aligned. This is okay to use if the caller knows a-priori
647 * that the pointer is suitably aligned (typically, because he just got it
648 * from palloc(), which always delivers a max-aligned pointer).
650 #define MemSetAligned(start, val, len) \
653 long *_start = (long *) (start); \
657 if ((_len & LONG_ALIGN_MASK) == 0 && \
659 _len <= MEMSET_LOOP_LIMIT && \
660 MEMSET_LOOP_LIMIT != 0) \
662 long *_stop = (long *) ((char *) _start + _len); \
663 while (_start < _stop) \
667 memset(_start, _val, _len); \
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
679 #define MemSetTest(val, len) \
680 ( ((len) & LONG_ALIGN_MASK) == 0 && \
681 (len) <= MEMSET_LOOP_LIMIT && \
682 MEMSET_LOOP_LIMIT != 0 && \
685 #define MemSetLoop(start, val, len) \
688 long * _start = (long *) (start); \
689 long * _stop = (long *) ((char *) _start + (Size) (len)); \
691 while (_start < _stop) \
697 * Macros to support compile-time assertion checks.
699 * If the "condition" (a compile-time-constant expression) evaluates to false,
700 * throw a compile error using the "errmessage" (a string literal).
702 * gcc 4.6 and up supports _Static_assert(), but there are bizarre syntactic
703 * placement restrictions. These macros make it safe to use as a statement
704 * or in an expression, respectively.
706 * Otherwise we fall back on a kluge that assumes the compiler will complain
707 * about a negative width for a struct bit-field. This will not include a
708 * helpful error message, but it beats not getting an error at all.
710 #ifdef HAVE__STATIC_ASSERT
711 #define StaticAssertStmt(condition, errmessage) \
712 do { _Static_assert(condition, errmessage); } while(0)
713 #define StaticAssertExpr(condition, errmessage) \
714 ({ StaticAssertStmt(condition, errmessage); true; })
715 #else /* !HAVE__STATIC_ASSERT */
716 #define StaticAssertStmt(condition, errmessage) \
717 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
718 #define StaticAssertExpr(condition, errmessage) \
719 StaticAssertStmt(condition, errmessage)
720 #endif /* HAVE__STATIC_ASSERT */
724 * Compile-time checks that a variable (or expression) has the specified type.
726 * AssertVariableIsOfType() can be used as a statement.
727 * AssertVariableIsOfTypeMacro() is intended for use in macros, eg
728 * #define foo(x) (AssertVariableIsOfTypeMacro(x, int), bar(x))
730 * If we don't have __builtin_types_compatible_p, we can still assert that
731 * the types have the same size. This is far from ideal (especially on 32-bit
732 * platforms) but it provides at least some coverage.
734 #ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
735 #define AssertVariableIsOfType(varname, typename) \
736 StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
737 CppAsString(varname) " does not have type " CppAsString(typename))
738 #define AssertVariableIsOfTypeMacro(varname, typename) \
739 ((void) StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
740 CppAsString(varname) " does not have type " CppAsString(typename)))
741 #else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
742 #define AssertVariableIsOfType(varname, typename) \
743 StaticAssertStmt(sizeof(varname) == sizeof(typename), \
744 CppAsString(varname) " does not have type " CppAsString(typename))
745 #define AssertVariableIsOfTypeMacro(varname, typename) \
746 ((void) StaticAssertExpr(sizeof(varname) == sizeof(typename), \
747 CppAsString(varname) " does not have type " CppAsString(typename)))
748 #endif /* HAVE__BUILTIN_TYPES_COMPATIBLE_P */
752 * Function inlining support -- Allow modules to define functions that may be
753 * inlined, if the compiler supports it.
755 * The function bodies must be defined in the module header prefixed by
756 * STATIC_IF_INLINE, protected by a cpp symbol that the module's .c file must
757 * define. If the compiler doesn't support inline functions, the function
758 * definitions are pulled in by the .c file as regular (not inline) symbols.
760 * The header must also declare the functions' prototypes, protected by
764 #define STATIC_IF_INLINE static inline
766 #define STATIC_IF_INLINE
767 #endif /* PG_USE_INLINE */
769 /* ----------------------------------------------------------------
770 * Section 7: random stuff
771 * ----------------------------------------------------------------
775 #define HIGHBIT (0x80)
776 #define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
778 #define STATUS_OK (0)
779 #define STATUS_ERROR (-1)
780 #define STATUS_EOF (-2)
781 #define STATUS_FOUND (1)
782 #define STATUS_WAITING (2)
786 * Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
787 * used in assert-enabled builds, to avoid compiler warnings about unused
788 * variables in assert-disabled builds.
790 #ifdef USE_ASSERT_CHECKING
791 #define PG_USED_FOR_ASSERTS_ONLY
793 #define PG_USED_FOR_ASSERTS_ONLY __attribute__((unused))
797 /* gettext domain name mangling */
800 * To better support parallel installations of major PostgeSQL
801 * versions as well as parallel installations of major library soname
802 * versions, we mangle the gettext domain name by appending those
803 * version numbers. The coding rule ought to be that whereever the
804 * domain name is mentioned as a literal, it must be wrapped into
805 * PG_TEXTDOMAIN(). The macros below do not work on non-literals; but
806 * that is somewhat intentional because it avoids having to worry
807 * about multiple states of premangling and postmangling as the values
808 * are being passed around.
810 * Make sure this matches the installation rules in nls-global.mk.
813 /* need a second indirection because we want to stringize the macro value, not the name */
814 #define CppAsString2(x) CppAsString(x)
816 #ifdef SO_MAJOR_VERSION
817 #define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
819 #define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
823 /* ----------------------------------------------------------------
824 * Section 8: system-specific hacks
826 * This should be limited to things that absolutely have to be
827 * included in every source file. The port-specific header file
828 * is usually a better place for this sort of thing.
829 * ----------------------------------------------------------------
833 * NOTE: this is also used for opening text files.
834 * WIN32 treats Control-Z as EOF in files opened in text mode.
835 * Therefore, we open files in binary mode on Win32 so we can read
836 * literal control-Z. The other affect is that we see CRLF, but
837 * that is OK because we can already handle those cleanly.
839 #if defined(WIN32) || defined(__CYGWIN__)
840 #define PG_BINARY O_BINARY
841 #define PG_BINARY_A "ab"
842 #define PG_BINARY_R "rb"
843 #define PG_BINARY_W "wb"
846 #define PG_BINARY_A "a"
847 #define PG_BINARY_R "r"
848 #define PG_BINARY_W "w"
852 * Provide prototypes for routines not present in a particular machine's
853 * standard C library.
856 #if !HAVE_DECL_SNPRINTF
858 snprintf(char *str, size_t count, const char *fmt,...)
859 /* This extension allows gcc to check the format string */
860 __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
863 #if !HAVE_DECL_VSNPRINTF
864 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
867 #if !defined(HAVE_MEMMOVE) && !defined(memmove)
868 #define memmove(d, s, c) bcopy(s, d, c)
871 /* no special DLL markers on most ports */
880 * The following is used as the arg list for signal handlers. Any ports
881 * that take something other than an int argument should override this in
882 * their pg_config_os.h file. Note that variable names are required
883 * because it is used in both the prototypes as well as the definitions.
884 * Note also the long name. We expect that this won't collide with
885 * other names causing compiler warnings.
889 #define SIGNAL_ARGS int postgres_signal_arg
893 * When there is no sigsetjmp, its functionality is provided by plain
894 * setjmp. Incidentally, nothing provides setjmp's functionality in
897 #ifndef HAVE_SIGSETJMP
898 #define sigjmp_buf jmp_buf
899 #define sigsetjmp(x,y) setjmp(x)
900 #define siglongjmp longjmp
903 #if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
904 extern int fdatasync(int fildes);
907 /* If strtoq() exists, rename it to the more standard strtoll() */
908 #if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOLL) && defined(HAVE_STRTOQ)
909 #define strtoll strtoq
910 #define HAVE_STRTOLL 1
913 /* If strtouq() exists, rename it to the more standard strtoull() */
914 #if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOULL) && defined(HAVE_STRTOUQ)
915 #define strtoull strtouq
916 #define HAVE_STRTOULL 1
920 * We assume if we have these two functions, we have their friends too, and
921 * can use the wide-character functions.
923 #if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
924 #define USE_WIDE_UPPER_LOWER
927 /* EXEC_BACKEND defines */
929 #define NON_EXEC_STATIC
931 #define NON_EXEC_STATIC static
934 /* /port compatibility functions */