xref: /unit/src/nxt_types.h (revision 703)
10Sigor@sysoev.ru 
20Sigor@sysoev.ru /*
30Sigor@sysoev.ru  * Copyright (C) Igor Sysoev
40Sigor@sysoev.ru  * Copyright (C) NGINX, Inc.
50Sigor@sysoev.ru  */
60Sigor@sysoev.ru 
70Sigor@sysoev.ru #ifndef _NXT_TYPES_H_INCLUDED_
80Sigor@sysoev.ru #define _NXT_TYPES_H_INCLUDED_
90Sigor@sysoev.ru 
100Sigor@sysoev.ru 
110Sigor@sysoev.ru /*
120Sigor@sysoev.ru  * nxt_int_t corresponds to the most efficient integer type,
130Sigor@sysoev.ru  * an architecture word.  It is usually the long type,
140Sigor@sysoev.ru  * but on Win64 the long is int32_t, so pointer size suits better.
150Sigor@sysoev.ru  * nxt_int_t must be no less than int32_t.
160Sigor@sysoev.ru  */
170Sigor@sysoev.ru 
180Sigor@sysoev.ru #if (__amd64__)
190Sigor@sysoev.ru /*
200Sigor@sysoev.ru  * AMD64 64-bit multiplication and division operations
210Sigor@sysoev.ru  * are slower and 64-bit instructions are longer.
220Sigor@sysoev.ru  */
230Sigor@sysoev.ru #define NXT_INT_T_SIZE       4
240Sigor@sysoev.ru typedef int                  nxt_int_t;
250Sigor@sysoev.ru typedef u_int                nxt_uint_t;
260Sigor@sysoev.ru 
270Sigor@sysoev.ru #else
280Sigor@sysoev.ru #define NXT_INT_T_SIZE       NXT_PTR_SIZE
290Sigor@sysoev.ru typedef intptr_t             nxt_int_t;
300Sigor@sysoev.ru typedef uintptr_t            nxt_uint_t;
310Sigor@sysoev.ru #endif
320Sigor@sysoev.ru 
330Sigor@sysoev.ru 
340Sigor@sysoev.ru typedef nxt_uint_t           nxt_bool_t;
350Sigor@sysoev.ru 
360Sigor@sysoev.ru 
370Sigor@sysoev.ru /*
380Sigor@sysoev.ru  * nxt_off_t corresponds to OS's off_t, a file offset type.
390Sigor@sysoev.ru  * Although Linux, Solaris, and HP-UX define both off_t and off64_t,
400Sigor@sysoev.ru  * setting _FILE_OFFSET_BITS to 64 defines off_t as off64_t.
410Sigor@sysoev.ru  */
420Sigor@sysoev.ru typedef off_t                nxt_off_t;
430Sigor@sysoev.ru 
440Sigor@sysoev.ru 
450Sigor@sysoev.ru /*
460Sigor@sysoev.ru  * nxt_time_t corresponds to OS's time_t, time in seconds.  nxt_time_t is
470Sigor@sysoev.ru  * a signed integer.  OS's time_t may be an integer or real-floating type,
480Sigor@sysoev.ru  * though it is usually a signed 32-bit or 64-bit integer depending on
490Sigor@sysoev.ru  * platform bit count.  There are however exceptions, e.g., time_t is:
500Sigor@sysoev.ru  *   32-bit on 64-bit NetBSD prior to 6.0 version;
510Sigor@sysoev.ru  *   64-bit on 32-bit NetBSD 6.0;
520Sigor@sysoev.ru  *   32-bit on 64-bit OpenBSD;
530Sigor@sysoev.ru  *   64-bit in Linux x32 ABI;
540Sigor@sysoev.ru  *   64-bit in 32-bit Visual Studio C++ 2005.
550Sigor@sysoev.ru  */
560Sigor@sysoev.ru #if (NXT_QNX)
570Sigor@sysoev.ru /*
580Sigor@sysoev.ru  * QNX defines time_t as uint32_t.
590Sigor@sysoev.ru  * Y2038 fix: "typedef int64_t  nxt_time_t".
600Sigor@sysoev.ru  */
610Sigor@sysoev.ru typedef int32_t              nxt_time_t;
620Sigor@sysoev.ru 
630Sigor@sysoev.ru #else
640Sigor@sysoev.ru /* Y2038, if time_t is 32-bit integer. */
650Sigor@sysoev.ru typedef time_t               nxt_time_t;
660Sigor@sysoev.ru #endif
670Sigor@sysoev.ru 
680Sigor@sysoev.ru 
690Sigor@sysoev.ru #if (NXT_PTR_SIZE == 8)
700Sigor@sysoev.ru #define NXT_64BIT            1
710Sigor@sysoev.ru #define NXT_32BIT            0
720Sigor@sysoev.ru 
730Sigor@sysoev.ru #else
740Sigor@sysoev.ru #define NXT_64BIT            0
750Sigor@sysoev.ru #define NXT_32BIT            1
760Sigor@sysoev.ru #endif
770Sigor@sysoev.ru 
780Sigor@sysoev.ru 
79*703Svbart@nginx.com #define NXT_INT64_T_LEN      nxt_length("-9223372036854775808")
80*703Svbart@nginx.com #define NXT_INT32_T_LEN      nxt_length("-2147483648")
810Sigor@sysoev.ru 
82*703Svbart@nginx.com #define NXT_INT64_T_HEXLEN   nxt_length("FFFFFFFFFFFFFFFF")
83*703Svbart@nginx.com #define NXT_INT32_T_HEXLEN   nxt_length("FFFFFFFF")
840Sigor@sysoev.ru 
85611Svbart@nginx.com #define NXT_INT64_T_MAX      0x7FFFFFFFFFFFFFFFLL
86611Svbart@nginx.com #define NXT_INT32_T_MAX      0x7FFFFFFF
870Sigor@sysoev.ru 
880Sigor@sysoev.ru 
890Sigor@sysoev.ru #if (NXT_INT_T_SIZE == 8)
900Sigor@sysoev.ru #define NXT_INT_T_LEN        NXT_INT64_T_LEN
910Sigor@sysoev.ru #define NXT_INT_T_HEXLEN     NXT_INT64_T_HEXLEN
920Sigor@sysoev.ru #define NXT_INT_T_MAX        NXT_INT64_T_MAX
930Sigor@sysoev.ru 
940Sigor@sysoev.ru #else
950Sigor@sysoev.ru #define NXT_INT_T_LEN        NXT_INT32_T_LEN
960Sigor@sysoev.ru #define NXT_INT_T_HEXLEN     NXT_INT32_T_HEXLEN
970Sigor@sysoev.ru #define NXT_INT_T_MAX        NXT_INT32_T_MAX
980Sigor@sysoev.ru #endif
990Sigor@sysoev.ru 
1000Sigor@sysoev.ru 
1010Sigor@sysoev.ru #if (NXT_64BIT)
1020Sigor@sysoev.ru #define NXT_ATOMIC_T_LEN     NXT_INT64_T_LEN
1030Sigor@sysoev.ru #define NXT_ATOMIC_T_HEXLEN  NXT_INT64_T_HEXLEN
1040Sigor@sysoev.ru #define NXT_ATOMIC_T_MAX     NXT_INT64_T_MAX
1050Sigor@sysoev.ru 
1060Sigor@sysoev.ru #else
1070Sigor@sysoev.ru #define NXT_ATOMIC_T_LEN     NXT_INT32_T_LEN
1080Sigor@sysoev.ru #define NXT_ATOMIC_T_HEXLEN  NXT_INT32_T_HEXLEN
1090Sigor@sysoev.ru #define NXT_ATOMIC_T_MAX     NXT_INT32_T_MAX
1100Sigor@sysoev.ru #endif
1110Sigor@sysoev.ru 
1120Sigor@sysoev.ru 
1130Sigor@sysoev.ru #if (NXT_OFF_T_SIZE == 8)
1140Sigor@sysoev.ru typedef uint64_t             nxt_uoff_t;
1150Sigor@sysoev.ru #define NXT_OFF_T_LEN        NXT_INT64_T_LEN
1160Sigor@sysoev.ru #define NXT_OFF_T_HEXLEN     NXT_INT64_T_HEXLEN
1170Sigor@sysoev.ru #define NXT_OFF_T_MAX        NXT_INT64_T_MAX
1180Sigor@sysoev.ru 
1190Sigor@sysoev.ru #else
1200Sigor@sysoev.ru typedef uint32_t             nxt_uoff_t;
1210Sigor@sysoev.ru #define NXT_OFF_T_LEN        NXT_INT32_T_LEN
1220Sigor@sysoev.ru #define NXT_OFF_T_HEXLEN     NXT_INT32_T_HEXLEN
1230Sigor@sysoev.ru #define NXT_OFF_T_MAX        NXT_INT32_T_MAX
1240Sigor@sysoev.ru #endif
1250Sigor@sysoev.ru 
1260Sigor@sysoev.ru 
1270Sigor@sysoev.ru #if (NXT_SIZE_T_SIZE == 8)
1280Sigor@sysoev.ru #define NXT_SIZE_T_LEN       NXT_INT64_T_LEN
1290Sigor@sysoev.ru #define NXT_SIZE_T_HEXLEN    NXT_INT64_T_HEXLEN
1300Sigor@sysoev.ru #define NXT_SIZE_T_MAX       NXT_INT64_T_MAX
1310Sigor@sysoev.ru 
1320Sigor@sysoev.ru #else
1330Sigor@sysoev.ru #define NXT_SIZE_T_LEN       NXT_INT32_T_LEN
1340Sigor@sysoev.ru #define NXT_SIZE_T_HEXLEN    NXT_INT32_T_HEXLEN
1350Sigor@sysoev.ru #define NXT_SIZE_T_MAX       NXT_INT32_T_MAX
1360Sigor@sysoev.ru #endif
1370Sigor@sysoev.ru 
1380Sigor@sysoev.ru 
1390Sigor@sysoev.ru #if (NXT_TIME_T_SIZE == 8)
1400Sigor@sysoev.ru #define NXT_TIME_T_LEN       NXT_INT64_T_LEN
1410Sigor@sysoev.ru #define NXT_TIME_T_HEXLEN    NXT_INT64_T_HEXLEN
1420Sigor@sysoev.ru #define NXT_TIME_T_MAX       NXT_INT64_T_MAX
1430Sigor@sysoev.ru 
1440Sigor@sysoev.ru #else
1450Sigor@sysoev.ru #define NXT_TIME_T_LEN       NXT_INT32_T_LEN
1460Sigor@sysoev.ru #define NXT_TIME_T_HEXLEN    NXT_INT32_T_HEXLEN
1470Sigor@sysoev.ru #define NXT_TIME_T_MAX       NXT_INT32_T_MAX
1480Sigor@sysoev.ru #endif
1490Sigor@sysoev.ru 
1500Sigor@sysoev.ru 
1510Sigor@sysoev.ru #endif /* _NXT_TYPES_H_INCLUDED_ */
152