1 2 /* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) NGINX, Inc. 5 */ 6 7 #ifndef _NJS_TYPES_H_INCLUDED_ 8 #define _NJS_TYPES_H_INCLUDED_ 9 10 11 #define NJS_OK 0 12 #define NJS_ERROR (-1) 13 #define NJS_AGAIN (-2) 14 #define NJS_DECLINED (-3) 15 #define NJS_DONE (-4) 16 17 18 /* 19 * off_t is 32 bit on Linux, Solaris and HP-UX by default. 20 * Must be before <sys/types.h>. 21 */ 22 #define _FILE_OFFSET_BITS 64 23 24 /* u_char, u_int, int8_t, int32_t, int64_t, size_t, off_t. */ 25 #include <sys/types.h> 26 #include <stdint.h> 27 28 29 #if (__LP64__) 30 #define NJS_64BIT 1 31 #define NJS_PTR_SIZE 8 32 #else 33 #define NJS_64BIT 0 34 #define NJS_PTR_SIZE 4 35 #endif 36 37 38 /* 39 * njs_int_t corresponds to the most efficient integer type, an architecture 40 * word. It is usually the long type, however on Win64 the long is int32_t, 41 * so pointer size suits better. njs_int_t must be no less than int32_t. 42 */ 43 44 #if (__amd64__) 45 /* 46 * AMD64 64-bit multiplication and division operations are slower and 64-bit 47 * instructions are longer. 48 */ 49 #define NJS_INT_T_SIZE 4 50 typedef int njs_int_t; 51 typedef u_int njs_uint_t; 52 53 #else 54 #define NJS_INT_T_SIZE NJS_PTR_SIZE 55 typedef intptr_t njs_int_t; 56 typedef uintptr_t njs_uint_t; 57 #endif 58 59 60 #if (NJS_HAVE_UNSIGNED_INT128) 61 typedef unsigned __int128 njs_uint128_t; 62 #endif 63 64 65 #if (NJS_INT_T_SIZE == 8) 66 #define NJS_INT_T_LEN NJS_INT64_T_LEN 67 #define NJS_INT_T_HEXLEN NJS_INT64_T_HEXLEN 68 #define NJS_INT_T_MAX NJS_INT64_T_MAX 69 70 #else 71 #define NJS_INT_T_LEN NJS_INT32_T_LEN 72 #define NJS_INT_T_HEXLEN NJS_INT32_T_HEXLEN 73 #define NJS_INT_T_MAX NJS_INT32_T_MAX 74 #endif 75 76 77 typedef njs_uint_t njs_bool_t; 78 typedef int njs_err_t; 79 80 81 /* 82 * njs_off_t corresponds to OS's off_t, a file offset type. Although Linux, 83 * Solaris, and HP-UX define both off_t and off64_t, setting _FILE_OFFSET_BITS 84 * to 64 defines off_t as off64_t. 85 */ 86 #if (NJS_WINDOWS) 87 /* Windows defines off_t as a 32-bit "long". */ 88 typedef __int64 njs_off_t; 89 90 #else 91 typedef off_t njs_off_t; 92 #endif 93 94 95 /* 96 * njs_time_t corresponds to OS's time_t, time in seconds. njs_time_t is 97 * a signed integer. OS's time_t may be an integer or real-floating type, 98 * though it is usually a signed 32-bit or 64-bit integer depending on 99 * platform bits length. There are however exceptions, e.g., time_t is: 100 * 32-bit on 64-bit NetBSD prior to 6.0 version; 101 * 64-bit on 32-bit NetBSD 6.0; 102 * 32-bit on 64-bit OpenBSD; 103 * 64-bit in Linux x32 ABI; 104 * 64-bit in 32-bit Visual Studio C++ 2005. 105 * 106 * Besides, QNX defines time_t as uint32_t. 107 */ 108 #if (NJS_QNX) 109 /* Y2038 fix: "typedef int64_t njs_time_t". */ 110 typedef int32_t njs_time_t; 111 112 #else 113 /* Y2038, if time_t is 32-bit integer. */ 114 typedef time_t njs_time_t; 115 #endif 116 117 118 typedef pid_t njs_pid_t; 119 120 121 #define NJS_INT32_T_LEN njs_length("-2147483648") 122 #define NJS_INT64_T_LEN njs_length("-9223372036854775808") 123 124 #define NJS_DOUBLE_LEN (1 + DBL_MAX_10_EXP) 125 126 #define NJS_MAX_ERROR_STR 2048 127 128 129 #endif /* _NJS_TYPES_H_INCLUDED_ */ 130