aboutsummaryrefslogtreecommitdiff
path: root/src/njs_types.h
blob: c38cb9dcf291250a7e91c7e9531902f1cb7f7a6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) NGINX, Inc.
 */

#ifndef _NJS_TYPES_H_INCLUDED_
#define _NJS_TYPES_H_INCLUDED_


#define NJS_OK             0
#define NJS_ERROR          (-1)
#define NJS_AGAIN          (-2)
#define NJS_DECLINED       (-3)
#define NJS_DONE           (-4)


/*
 * off_t is 32 bit on Linux, Solaris and HP-UX by default.
 * Must be before <sys/types.h>.
 */
#define _FILE_OFFSET_BITS  64

/* u_char, u_int, int8_t, int32_t, int64_t, size_t, off_t. */
#include <sys/types.h>
#include <stdint.h>


#if (__LP64__)
#define NJS_64BIT       1
#define NJS_PTR_SIZE    8
#else
#define NJS_64BIT       0
#define NJS_PTR_SIZE    4
#endif


/*
 * njs_int_t corresponds to the most efficient integer type, an architecture
 * word.  It is usually the long type, however on Win64 the long is int32_t,
 * so pointer size suits better.  njs_int_t must be no less than int32_t.
 */

#if (__amd64__)
/*
 * AMD64 64-bit multiplication and division operations are slower and 64-bit
 * instructions are longer.
 */
#define NJS_INT_T_SIZE  4
typedef int             njs_int_t;
typedef u_int           njs_uint_t;

#else
#define NJS_INT_T_SIZE  NJS_PTR_SIZE
typedef intptr_t        njs_int_t;
typedef uintptr_t       njs_uint_t;
#endif


#if (NJS_HAVE_UNSIGNED_INT128)
typedef unsigned __int128 njs_uint128_t;
#endif


#if (NJS_INT_T_SIZE == 8)
#define NJS_INT_T_LEN        NJS_INT64_T_LEN
#define NJS_INT_T_HEXLEN     NJS_INT64_T_HEXLEN
#define NJS_INT_T_MAX        NJS_INT64_T_MAX

#else
#define NJS_INT_T_LEN        NJS_INT32_T_LEN
#define NJS_INT_T_HEXLEN     NJS_INT32_T_HEXLEN
#define NJS_INT_T_MAX        NJS_INT32_T_MAX
#endif


typedef njs_uint_t      njs_bool_t;
typedef int             njs_err_t;


/*
 * njs_off_t corresponds to OS's off_t, a file offset type.  Although Linux,
 * Solaris, and HP-UX define both off_t and off64_t, setting _FILE_OFFSET_BITS
 * to 64 defines off_t as off64_t.
 */
#if (NJS_WINDOWS)
/* Windows defines off_t as a 32-bit "long". */
typedef __int64        njs_off_t;

#else
typedef off_t          njs_off_t;
#endif


/*
 * njs_time_t corresponds to OS's time_t, time in seconds.  njs_time_t is
 * a signed integer.  OS's time_t may be an integer or real-floating type,
 * though it is usually a signed 32-bit or 64-bit integer depending on
 * platform bits length.  There are however exceptions, e.g., time_t is:
 *   32-bit on 64-bit NetBSD prior to 6.0 version;
 *   64-bit on 32-bit NetBSD 6.0;
 *   32-bit on 64-bit OpenBSD;
 *   64-bit in Linux x32 ABI;
 *   64-bit in 32-bit Visual Studio C++ 2005.
 *
 * Besides, QNX defines time_t as uint32_t.
 */
#if (NJS_QNX)
/* Y2038 fix: "typedef int64_t  njs_time_t". */
typedef int32_t        njs_time_t;

#else
/* Y2038, if time_t is 32-bit integer. */
typedef time_t         njs_time_t;
#endif


typedef pid_t          njs_pid_t;


#define NJS_INT32_T_LEN      njs_length("-2147483648")
#define NJS_INT64_T_LEN      njs_length("-9223372036854775808")

#define NJS_DOUBLE_LEN       (1 + DBL_MAX_10_EXP)

#define NJS_MAX_ERROR_STR    2048


#endif /* _NJS_TYPES_H_INCLUDED_ */