1/*
2 * PROGRAM: JRD access method
3 * MODULE: common.h
4 * DESCRIPTION: Common descriptions for all GDS programs
5 *
6 * The contents of this file are subject to the Interbase Public
7 * License Version 1.0 (the "License"); you may not use this file
8 * except in compliance with the License. You may obtain a copy
9 * of the License at http://www.Inprise.com/IPL.html
10 *
11 * Software distributed under the License is distributed on an
12 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * rights and limitations under the License.
15 *
16 * The Original Code was created by Inprise Corporation
17 * and its predecessors. Portions created by Inprise Corporation are
18 * Copyright (C) Inprise Corporation.
19 *
20 * All Rights Reserved.
21 * Contributor(s): ______________________________________.
22 *
23 * 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE"
24 * conditionals, as the engine now fully supports
25 * readonly databases.
26 *
27 * 2001.11.20 Ann Harrison - make 64bitio.h conditional on not windows.
28 *
29 * 2002.02.15 Sean Leyne - Code Cleanup, removed obsolete ports:
30 * - MAC ("MAC", "MAC_AUX" and "MAC_CP" defines)
31 * - EPSON, XENIX, DELTA, IMP, NCR3000, M88K
32 * - NT Power PC and HP9000 s300
33 *
34 * 2002.04.16 Paul Beach - HP10 and unistd.h
35 *
36 * 2002.10.27 Sean Leyne - Completed removal of obsolete "DG_X86" port
37 * 2002.10.27 Sean Leyne - Code Cleanup, removed obsolete "UNIXWARE" port
38 * 2002.10.27 Sean Leyne - Code Cleanup, removed obsolete "Ultrix" port
39 *
40 * 2002.10.28 Sean Leyne - Completed removal of obsolete "DGUX" port
41 * 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "DecOSF" port
42 * 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "SGI" port
43 *
44 * 2002.10.29 Sean Leyne - Removed obsolete "Netware" port
45 *
46 * 2002.10.30 Sean Leyne - Removed support for obsolete "PC_PLATFORM" define
47 *
48 */
49
50#ifndef COMMON_COMMON_H
51#define COMMON_COMMON_H
52
53#ifdef HAVE_STDLIB_H
54#include <stdlib.h>
55#endif
56
57#ifdef HAVE_SYS_PARAM_H
58#include <sys/param.h>
59#endif
60
61#ifdef HAVE_UNISTD_H
62// for _POSIX_THREADS test below
63#include <unistd.h>
64#endif
65
66#if defined(_POSIX_THREADS) && _POSIX_THREADS >= 200112L
67// above check is generally true. However, we use pthreads on some platforms
68// where _POSIX_THREADS is defined to "1" or not even defined at all!
69#define USE_POSIX_THREADS
70#endif
71
72#include "fb_macros.h"
73#include "fb_types.h"
74
75/*
76 do not use links in source code to maintain platform neutrality
77*/
78
79
80/*****************************************************
81* Linux platforms
82*****************************************************/
83#ifdef LINUX
84#define QUADFORMAT "ll"
85#define QUADCONST(n) (n##LL)
86
87#define FB_OS OsLinux
88
89#ifdef __GNUC__
90#define FB_CC CcGcc
91#else
92#define FB_CC CcIcc
93#endif
94
95// SLONG is a 32-bit integer on 64-bit platforms
96//#if SIZEOF_LONG == 4
97//#define SLONGFORMAT "ld"
98//#define ULONGFORMAT "lu"
99//#define XLONGFORMAT "lX"
100//#define xLONGFORMAT "lx"
101//#endif
102
103// format for size_t
104#ifndef SIZEFORMAT
105#define SIZEFORMAT "zi"
106#endif
107
108//format for __LINE__
109#define LINEFORMAT "d"
110
111#define UNIX
112#define IEEE
113
114#ifdef AMD64
115#define FB_CPU CpuAmd
116
117// on buggy kernels ERESTARTNOHAND (==514) may be returned instead of EINTR
118// use value '514' instead of ERESTARTNOHAND cause it's not present in std includes
119// in theory such error codes should never be seen outside kernel
120#define SYSCALL_INTERRUPTED(err) (((err) == EINTR) || ((err) == 514)) /* pjpg 20001102 */
121
122#endif
123
124#ifdef PPC
125#define FB_CPU CpuPowerPc
126#endif
127
128#ifdef i386
129#define I386
130#define FB_CPU CpuIntel
131#endif /* i386 */
132
133#ifdef ARM
134#define FB_CPU CpuArm
135#endif /* ARM */
136
137#ifdef sparc
138#define FB_CPU CpuUltraSparc
139#define RISC_ALIGNMENT
140#endif /* sparc */
141
142#ifdef MIPSEL
143#define FB_CPU CpuMipsel
144#endif /* mipsel */
145
146#ifdef MIPSEB
147#define FB_CPU CpuMips
148#endif /* mips */
149
150#ifdef IA64
151#define FB_CPU CpuIa64
152#define RISC_ALIGNMENT
153#endif // IA64
154
155#ifndef USE_POSIX_THREADS
156// force pthread detection on Linux for distros that do not provide
157// POSIX thread compatability
158#define USE_POSIX_THREADS
159#endif
160
161#ifdef __s390__
162#ifdef __s390x__
163#define FB_CPU CpuS390x
164#else
165#define FB_CPU CpuS390
166#endif // __s390x__
167#endif // __s390__
168
169#ifdef SH
170#define FB_CPU CpuSh
171#define RISC_ALIGNMENT
172#endif /* sh */
173
174#ifdef SHEB
175#define FB_CPU CpuSheb
176#define RISC_ALIGNMENT
177#endif /* sheb */
178
179#ifdef HPPA
180#define FB_CPU CpuHppa
181#define RISC_ALIGNMENT
182#endif /* hppa */
183
184#ifdef ALPHA
185#define FB_CPU CpuAlpha
186#define RISC_ALIGNMENT
187#endif
188
189#endif /* LINUX */
190
191
192/*****************************************************
193* Darwin Platforms
194*****************************************************/
195#ifdef DARWIN
196
197//format for __LINE__
198#define LINEFORMAT "d"
199
200//#define SLONGFORMAT "ld"
201//#define ULONGFORMAT "lu"
202//#define XLONGFORMAT "lX"
203//#define xLONGFORMAT "lx"
204
205#define FB_CC CcGcc
206
207#define UNIX
208#define FB_OS OsDarwin
209#ifdef __ppc__
210#define powerpc
211#define FB_CPU CpuPowerPc
212#endif
213#ifdef i386
214#define I386
215#define FB_CPU CpuIntel
216#endif
217#ifdef __x86_64__
218#define DARWIN64
219#define FB_CPU CpuAmd
220#endif
221#ifdef __ppc64__
222#define DARWINPPC64
223#define FB_CPU CpuPowerPc64
224#endif
225#define IEEE
226#define QUADCONST(n) (n##LL)
227#define QUADFORMAT "q"
228//#define MAP_ANON correctly defined in sys/mman.h
229
230#define API_ROUTINE __attribute__((visibility("default")))
231#define API_ROUTINE_VARARG API_ROUTINE
232#define INTERNAL_API_ROUTINE API_ROUTINE
233#define FB_EXPORTED __attribute__((visibility("default")))
234
235#define O_DIRECT F_NOCACHE
236#endif /* Darwin Platforms */
237
238
239/*****************************************************
240* FreeBSD for Intel platforms
241*****************************************************/
242#ifdef FREEBSD
243
244#define FB_OS OsFreeBsd
245#define FB_CC CcGcc
246
247#define UNIX
248#define IEEE
249
250#ifdef AMD64
251#define FB_CPU CpuAmd
252#else
253#define I386
254#define FB_CPU CpuIntel
255#endif
256
257#define QUADFORMAT "ll"
258#define QUADCONST(n) (n##LL)
259#define NO_NFS /* no MTAB_OPEN or MTAB_CLOSE in isc_file.c */
260
261#ifndef USE_POSIX_THREADS
262// force pthread detection on FREEBSD
263#define USE_POSIX_THREADS
264#endif
265
266#endif /* FREEBSD */
267
268/*****************************************************
269* NetBSD
270*****************************************************/
271#ifdef NETBSD
272
273#define FB_OS OsNetBsd
274#define FB_CC CcGcc
275
276#if defined(__i386__)
277
278#define IEEE
279#define I386
280#define FB_CPU CpuIntel
281
282#define QUADFORMAT "ll"
283#define QUADCONST(n) (n##LL)
284#else /* !__i386__ */
285#error Please add support for other ports
286#endif
287
288#define UNIX
289#define NO_NFS /* no MTAB_OPEN or MTAB_CLOSE in isc_file.c */
290
291#endif /* NETBSD */
292
293
294/*****************************************************
295* Android
296*****************************************************/
297#ifdef ANDROID
298
299#define NO_NFS /* no MTAB_OPEN or MTAB_CLOSE in isc_file.c */
300
301#endif /* NETBSD */
302
303
304/*****************************************************
305 * SUN platforms--the 386i is obsolete
306*****************************************************/
307
308#ifdef __sun
309
310#ifdef SOLARIS
311
312#define FB_OS OsSolaris
313
314#ifdef __GNUC__
315#define FB_CC CcGcc
316#else
317#define FB_CC CcSunStudio
318#endif
319
320/* Define the following only on platforms whose standard I/O
321 * implementation is so weak that we wouldn't be able to fopen
322 * a file whose underlying file descriptor would be > 255.
323 * Hey, we're not running on PDP-11's any more: would it kill you
324 * to use a short instead of a char to hold the fileno? :-(
325 */
326
327/* Why we (solarises) need to rewrite old BSD stdio
328 so many times I suggest stdIO from
329 http://www.research.att.com/sw/tools/sfio/
330*/
331/* Need to use full sfio not just stdio emulation to fix
332 file descriptor number limit. nmcc Dec2002
333*/
334
335/* Update for Solaris 10. The problem still exists pre Solaris 10,
336however if you are using a version of Solaris 10 after 11/06 the
337problem with file descriptors has been solved and this define and
338the following function can now be commented out.
339If you are using Solaris 10 from 03/05 - 11/06 you need to patch
340your operating system.
341Earlier versions of Solaris still have the problem. pbeach Feb2010
342*/
343
344#if (!defined(__arch64__)) && (!defined(SFIO))
345#error "need to use SFIO"
346#endif
347
348// this function is normally defined in stdio.h, but is missing in SFIO's h-file
349extern "C" int remove(const char* path);
350
351/* The following define is the prefix to go in front of a "d" or "u"
352 format item in a printf() format string, to indicate that the argument
353 is an SINT64 or FB_UINT64. */
354#define QUADFORMAT "ll"
355/* The following macro creates a quad-sized constant, possibly one
356 which is too large to fit in a long int. */
357#define QUADCONST(n) (n##LL)
358
359#ifndef USE_POSIX_THREADS
360#if defined(_POSIX_THREADS) && _POSIX_THREADS >= 1L
361// Solaris 9 has _POSIX_THREADS = 1L
362// Solaris 10 has _POSIX_THREADS >= 200112L
363#define USE_POSIX_THREADS
364#endif
365#endif
366
367#endif // SOLARIS
368
369#define UNIX
370#define IEEE
371
372#ifdef __sparc
373#define FB_CPU CpuUltraSparc
374#define RISC_ALIGNMENT
375
376#elif defined (__amd64)
377#define FB_CPU CpuAmd
378
379#elif defined (__i386)
380#define FB_CPU CpuIntel
381
382#else
383#error What is FB_CPU for this Solaris platform????
384#endif
385
386#endif // __sun
387
388
389/*****************************************************
390* HP/UX platforms
391*****************************************************/
392
393#ifdef HPUX
394
395#define USE_SHMEM_EXT // Looks like everyone else can ISC_remap
396
397#define UNIX
398
399#define FB_OS OsHpux
400
401#if defined (__HP_aCC)
402#define FB_CC CcAcc
403#undef HAVE___THREAD // aCC error, __thread can be used only with C-like structs
404#elif defined (__GNUC__)
405#define FB_CC CcGcc
406#endif
407
408#define IEEE
409// 16-Apr-2002 HP10 in unistd.h Paul Beach
410//#define setreuid(ruid, euid) setresuid (ruid, euid, -1)
411//#define setregid(rgid, egid) setresgid (rgid, egid, -1)
412
413/* The following define is the prefix to go in front of a "d" or "u"
414 format item in a printf() format string, to indicate that the argument
415 is an SINT64 or FB_UINT64. */
416#define QUADFORMAT "ll"
417/* The following macro creates a quad-sized constant, possibly one
418 which is too large to fit in a long int. */
419#define QUADCONST(n) (n)
420
421#ifndef USE_POSIX_THREADS
422// HPUX v B.11.23 does not have _POSIX_THREADS defined, their implementation
423// is incomplete, but good enough for us
424#define USE_POSIX_THREADS
425#endif
426
427#error Need a way to define CpuHppa or CpuIa64
428#define FB_CPU
429
430#define RISC_ALIGNMENT
431
432#endif /* HPUX */
433
434
435/*****************************************************
436* IBM AIX PowerPC
437*****************************************************/
438
439#ifdef _AIX /* IBM AIX */
440
441#define FB_OS OsAix
442#define FB_CC CcXlc
443
444#if SIZEOF_VOID_P == 4
445#define FB_CPU CpuPowerPc
446#endif
447#if SIZEOF_VOID_P == 8
448#define FB_CPU CpuPowerPc64
449#endif
450
451#define AIX
452#define AIX_PPC
453#define UNIX
454
455#define IEEE
456#define SYSCALL_INTERRUPTED(err) (((err) == EINTR) || ((err) == ERESTART)) /* pjpg 20001102 */
457
458#define QUADFORMAT "ll" /* TMC 081700 */
459#define QUADCONST(n) (n##LL) /* TMC 081700 */
460
461// AIX does not pass autoconf's test for mmap() correctness,
462// but we do not use flag (MAP_FIXED) that fails.
463#define HAVE_MMAP
464
465// autoconf test AC_SYS_LARGEFILE defines _LARGE_FILES for AIX builds.
466// But, in <standards.h>, _LARGE_FILE_API is defined, leading to conflict
467// in 32-bit builds. Only one of these macros should be defined.
468#undef _LARGE_FILE_API
469
470#endif /* IBM AIX */
471
472
473
474/*****************************************************
475* Windows NT
476*****************************************************/
477
478#ifdef WIN_NT
479
480#define NO_NFS
481
482#define FB_OS OsWindows
483
484#ifdef __GNUC__
485#define FB_CC CcGcc
486#elif defined(_MSC_VER)
487#define FB_CC CcMsvc
488#endif
489
490#define SYS_ERR Arg::Windows
491//#define SLONGFORMAT "ld"
492//#define ULONGFORMAT "lu"
493//#define XLONGFORMAT "lX"
494//#define xLONGFORMAT "lx"
495
496//format for __LINE__
497#define LINEFORMAT "d"
498
499/* The following define is the prefix to go in front of a "d" or "u"
500 format item in a printf() format string, to indicate that the argument
501 is an SINT64 or FB_UINT64. */
502#define QUADFORMAT "I64"
503/* The following macro creates a quad-sized constant, possibly one
504 which is too large to fit in a long int. The Microsoft compiler does
505 not permit the LL suffix which some other platforms require, but it
506 handles numbers up to the largest 64-bit integer correctly without such
507 a suffix, so the macro definition is trivial. */
508#ifdef __GNUC__ // needed for gcc 3.3.1
509#define QUADCONST(n) (n##LL)
510#else
511#define QUADCONST(n) (n)
512#endif
513
514#ifdef AMD64
515#define FB_CPU CpuAmd
516#else
517#ifndef I386
518#define I386
519#endif
520#define FB_CPU CpuIntel
521#endif
522
523#define IEEE
524#define API_ROUTINE __stdcall
525#define API_ROUTINE_VARARG __cdecl
526#define CLIB_ROUTINE __cdecl
527
528#ifndef MAXPATHLEN
529#ifdef MAX_PATH
530#define MAXPATHLEN MAX_PATH
531#else
532#define MAXPATHLEN 260
533#endif
534#endif
535
536#define ERRNO GetLastError()
537#define INET_ERRNO WSAGetLastError()
538#define H_ERRNO WSAGetLastError()
539
540// For Visual Studio 2003 and earlier enable Windows 9X support
541#if defined _MSC_VER && (_MSC_VER < 1400)
542#define WIN9X_SUPPORT
543#endif
544
545#endif /* WIN_NT */
546
547
548#ifndef FB_CPU
549#error Define FB_CPU for your platform
550#endif
551#ifndef FB_OS
552#error Define FB_OS for your platform
553#endif
554#ifndef FB_CC
555#error Define FB_CC for your platform
556#endif
557
558
559/*****************************************************
560 * UNIX
561*****************************************************/
562#ifdef UNIX
563#define SYS_ERR Arg::Unix
564#endif /* UNIX */
565
566#ifndef SYS_ERR
567#define SYS_ERR Arg::Unix
568#endif
569
570#ifndef ERRNO
571#define ERRNO errno
572#endif
573
574#ifndef INET_ERRNO
575#define INET_ERRNO errno
576#endif
577
578#ifndef H_ERRNO
579#define H_ERRNO h_errno
580#endif
581
582/* various declaration modifiers */
583
584#ifndef API_ROUTINE
585#define API_ROUTINE
586#define API_ROUTINE_VARARG
587#endif
588
589#ifndef CLIB_ROUTINE
590#define CLIB_ROUTINE
591#endif
592
593#ifndef FB_EXPORTED
594#define FB_EXPORTED
595#endif
596
597
598/* alignment macros */
599
600#ifndef OLD_ALIGNMENT
601#ifdef I386
602/* Using internal alignment optimal for 386 processor and above
603 */
604//#define FB_ALIGNMENT 4
605//#define FB_DOUBLE_ALIGN 8
606#endif
607#endif
608
609#ifndef FB_ALIGNMENT
610#error must define FB_ALIGNMENT for your system
611#endif
612
613#ifndef SHIFTLONG
614/* Number of shifts needed to convert between char and LONG */
615#define SHIFTLONG 2
616#define BITS_PER_LONG 32
617#endif
618
619#ifndef FB_DOUBLE_ALIGN
620#error must define FB_DOUBLE_ALIGN for your system
621#endif
622
623
624
625/* common return values */
626
627#ifndef FINI_OK
628#define FINI_OK 0
629#define FINI_ERROR 1
630#define STARTUP_ERROR 2 /* this is also used in iscguard.h, make sure these match */
631#endif
632
633#ifndef TRUE
634#define TRUE 1
635#endif
636#ifndef FALSE
637#define FALSE 0
638#endif
639#define FB_SUCCESS 0
640#define FB_FAILURE 1
641
642/* sys/paramh.h : compatibility purposes */
643#ifndef NOFILE
644#define NOFILE 20
645#endif
646
647/* data type definitions */
648
649#ifndef ISC_TIMESTAMP_DEFINED
650typedef SLONG ISC_DATE;
651typedef ULONG ISC_TIME;
652struct ISC_TIMESTAMP
653{
654 ISC_DATE timestamp_date;
655 ISC_TIME timestamp_time;
656};
657#define ISC_TIMESTAMP_DEFINED
658#endif /* ISC_TIMESTAMP_DEFINED */
659
660#define GDS_DATE ISC_DATE
661#define GDS_TIME ISC_TIME
662#define GDS_TIMESTAMP ISC_TIMESTAMP
663
664
665#ifndef BLOB_PTR
666#define BLOB_PTR UCHAR
667#endif
668
669
670#ifndef SLONGFORMAT
671#if SIZEOF_LONG == 4
672#define SLONGFORMAT "ld"
673#define ULONGFORMAT "lu"
674#define XLONGFORMAT "lX"
675#define xLONGFORMAT "lx"
676#else
677#define SLONGFORMAT "d"
678#define ULONGFORMAT "u"
679#define XLONGFORMAT "X"
680#define xLONGFORMAT "x"
681#endif
682#endif
683
684// Shortcuts to make it easier to convert code using SLONGFORMAT/ULONGFORMAT
685#define UQUADFORMAT QUADFORMAT"u"
686#define SQUADFORMAT QUADFORMAT"d"
687
688// format for size_t
689#ifndef SIZEFORMAT
690#if (SIZEOF_SIZE_T == 8)
691#define SIZEFORMAT UQUADFORMAT
692#else
693#define SIZEFORMAT ULONGFORMAT
694#endif
695#endif // SIZEFORMAT
696
697// format for __LINE__
698#ifndef LINEFORMAT
699#ifdef __GNUC__
700#define LINEFORMAT "d"
701#else
702#define LINEFORMAT "ld"
703#endif // __GNUC__
704#endif
705
706// format for OS handles
707#if defined(WIN_NT) && (SIZEOF_VOID_P == 8)
708#define HANDLEFORMAT SQUADFORMAT
709#else
710#define HANDLEFORMAT SLONGFORMAT
711#endif
712
713
714/* conditional compilation macros */
715
716/* MAX and MIN for datatypes */
717
718#define MAX_UCHAR ((UCHAR)0xFF)
719#define MIN_UCHAR 0x00
720
721#define MAX_SCHAR 0x7F
722#define MIN_SCHAR (-MAX_SCHAR - 1)
723
724#define MAX_USHORT ((USHORT)0xFFFF)
725#define MIN_USHORT 0x0000
726
727#define MAX_SSHORT 0x7FFF
728#define MIN_SSHORT (-MAX_SSHORT - 1)
729
730#define MAX_ULONG ((ULONG)0xFFFFFFFF)
731#define MIN_ULONG 0x00000000
732
733#define MAX_SLONG 0x7FFFFFFF
734#define MIN_SLONG (-MAX_SLONG - 1)
735
736#define MAX_UINT64 ((FB_UINT64) QUADCONST(0xFFFFFFFFFFFFFFFF))
737#define MIN_UINT64 QUADCONST(0x0000000000000000)
738
739#define MAX_SINT64 QUADCONST(0x7FFFFFFFFFFFFFFF)
740#define MIN_SINT64 (-MAX_SINT64 - 1)
741
742
743
744/* commonly used macros */
745
746#ifndef MAX
747#define MAX(a, b) (((a) > (b)) ? (a) : (b))
748#endif
749#ifndef MIN
750#define MIN(a, b) (((a) < (b)) ? (a) : (b))
751#endif
752
753#define UPPER(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 'a' + 'A' : (c))
754#define LOWWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
755
756/* UPPER7 & LOWWER7 are to be used when the data is known to
757 be 7-bit ASCII, eg: internal data, OS data. NOT user data. */
758
759#define UPPER7(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 'a' + 'A' : (c))
760#define LOWWER7(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
761
762#ifndef ROUNDUP
763#define ROUNDUP(n, b) (((n) + (b) - 1) & ~((b) - 1))
764#endif
765#define ROUNDUP_LONG(len) ROUNDUP (len, sizeof (SLONG))
766
767#define JRD_BUGCHK 15 /* facility code for bugcheck messages */
768#ifndef OFFSET
769#define OFFSET(struct, fld) ((size_t) &((struct) NULL)->fld)
770#define OFFSETA(struct, fld) ((size_t) ((struct) NULL)->fld)
771#endif
772
773#ifndef ODS_ALIGNMENT
774#define ODS_ALIGNMENT 4
775#endif
776
777#ifndef FORMAT_ALIGNMENT
778// Alignment for items in record format. Used for databases after ODS11.
779// Always 64-bit to ensure ODS compatibility with 64-bit versions of the engine
780#define FORMAT_ALIGNMENT 8
781#endif
782
783#ifndef SYSCALL_INTERRUPTED
784#define SYSCALL_INTERRUPTED(err) ((err) == EINTR)
785#endif
786
787
788/* data movement and allocation macros */
789
790#define MOVE_CLEAR(to, length) memset(to, 0, (size_t) (length))
791
792// This macros are used to workaround shortage of standard conformance
793// in Microsoft compilers. They could be replaced with normal procedure
794// and generic macro if MSVC would support C99-style __VA_ARGS__
795#define DEFINE_TRACE_ROUTINE(routine) void routine(const char* message, ...)
796
797#ifdef HAVE_VSNPRINTF
798#define VSNPRINTF(a, b, c, d) vsnprintf(a, b, c, d)
799#else
800#define VSNPRINTF(a, b, c, d) vsprintf(a, c, d)
801#endif
802
803#ifdef HAVE_SNPRINTF
804#define SNPRINTF snprintf
805#else
806#define SNPRINTF(buffer, length, ...) sprintf(buffer, __VA_ARGS__)
807#endif
808
809#define IMPLEMENT_TRACE_ROUTINE(routine, subsystem) \
810void routine(const char* message, ...) \
811{ \
812 Firebird::string format(subsystem ","); \
813 format += message; \
814 Firebird::string buffer; \
815 va_list params; \
816 va_start(params, message); \
817 buffer.vprintf(format.c_str(), params); \
818 va_end(params); \
819 gds__trace(buffer.c_str()); \
820}
821
822#ifdef DEV_BUILD
823
824/* Define any debugging symbols and macros here. This
825 ifdef will be executed during development builds. */
826
827#define TRACE(msg) gds__trace (msg)
828
829#ifndef DEV_REPORT
830#define DEV_REPORT(msg) gds__log (msg)
831#endif
832
833#ifndef BREAKPOINT
834#define BREAKPOINT(x) GDS_breakpoint(x)
835// fwd. decl. the function itself
836#ifdef __cplusplus
837extern "C" {
838#endif
839void GDS_breakpoint(int);
840#ifdef __cplusplus
841} /* extern "C" */
842#endif
843#endif
844
845#endif /* DEV_BUILD */
846
847#ifndef DEV_BUILD
848#ifndef DEV_REPORT
849#define DEV_REPORT(msg) gds__log (msg)
850#endif
851#ifndef BREAKPOINT
852#define BREAKPOINT(x) /* nothing */
853#endif
854#ifndef TRACE
855#define TRACE(msg) /* nothing */
856#endif
857#endif
858
859
860/* commonly used buffer sizes for dynamic buffer allocation */
861
862#define BUFFER_XLARGE 2048
863#define BUFFER_LARGE 1024
864#define BUFFER_MEDIUM 512
865#define BUFFER_SMALL 256
866#define BUFFER_TINY 128
867
868/* The default lseek offset type. Changed from nothing to (off_t) to correctly support 64 bit IO */
869#ifndef LSEEK_OFFSET_CAST
870#define LSEEK_OFFSET_CAST (off_t)
871#endif
872
873#define STRINGIZE_AUX(x) #x
874#define STRINGIZE(x) STRINGIZE_AUX(x)
875
876#ifdef _MSC_VER
877#define FB_CONST64(a) (a##i64)
878#else
879#define FB_CONST64(a) (a##LL)
880#endif
881
882// Check for "final" keyword support
883#ifdef __GNUC__
884#if ((__GNUC__ == 4 && __GNUC_MINOR__ >= 7) || (__GNUC__ >= 5))
885#define FB_FINAL __final
886#endif
887#endif
888// Please add support for other compilers here
889#ifndef FB_FINAL
890#define FB_FINAL
891#endif
892
893#define FB_UNUSED(value) do { if (value); } while (false)
894
895// 30 Dec 2002. Nickolay Samofatov
896// This needs to be checked for all supported platforms
897// The simpliest way to check it is to issue from correct client:
898// declare external function abs2 double precision
899// returns double precision by value
900// entry_point 'IB_UDF_abs' module_name 'ib_udf';
901// select abs2(2.0 / 3.0) from rdb$database;
902// It will return big strange value in case of invalid define
903
904// ASF: Currently, all little-endian are FB_SWAP_DOUBLE and big-endian aren't.
905// AP: Define it for your hardware correctly in case your CPU do not follow mentioned rule.
906// The follwoing lines are kept for reference only.
907//#if defined(i386) || defined(I386) || defined(_M_IX86) || defined(AMD64) || defined(ARM) || defined(MIPSEL) || defined(DARWIN64) || defined(IA64)
908//#define FB_SWAP_DOUBLE 1
909//#elif defined(sparc) || defined(PowerPC) || defined(PPC) || defined(__ppc__) || defined(HPUX) || defined(MIPS) || defined(__ppc64__)
910//#define FB_SWAP_DOUBLE 0
911//#else
912//#error "Define FB_SWAP_DOUBLE for your platform correctly !"
913//#endif
914
915#ifndef FB_SWAP_DOUBLE
916#ifdef WORDS_BIGENDIAN
917#define FB_SWAP_DOUBLE 0
918#else
919#define FB_SWAP_DOUBLE 1
920#endif
921#endif
922
923// Commonly used indices to access parts of double in correct order.
924#if FB_SWAP_DOUBLE
925#define FB_LONG_DOUBLE_FIRST 1
926#define FB_LONG_DOUBLE_SECOND 0
927#else
928#define FB_LONG_DOUBLE_FIRST 0
929#define FB_LONG_DOUBLE_SECOND 1
930#endif
931
932// Used in quad operations
933#ifndef WORDS_BIGENDIAN
934const int LOW_WORD = 0;
935const int HIGH_WORD = 1;
936#else
937const int LOW_WORD = 1;
938const int HIGH_WORD = 0;
939#endif
940
941#ifndef HAVE_WORKING_VFORK
942#define vfork fork
943#endif
944
945
946// In many cases we need to assign wrong handle value to closed handle
947// Some OSes define it, others - not
948#ifndef WIN_NT
949#ifndef INVALID_HANDLE_VALUE
950#define INVALID_HANDLE_VALUE (-1)
951#endif
952#endif
953
954static const TEXT FB_SHORT_MONTHS[][4] =
955{
956 "Jan", "Feb", "Mar",
957 "Apr", "May", "Jun",
958 "Jul", "Aug", "Sep",
959 "Oct", "Nov", "Dec",
960 "\0"
961};
962
963static const TEXT* const FB_LONG_MONTHS_UPPER[] =
964{
965 "JANUARY",
966 "FEBRUARY",
967 "MARCH",
968 "APRIL",
969 "MAY",
970 "JUNE",
971 "JULY",
972 "AUGUST",
973 "SEPTEMBER",
974 "OCTOBER",
975 "NOVEMBER",
976 "DECEMBER",
977 0
978};
979
980#endif /* COMMON_COMMON_H */
981
982