1 /* 2 ** Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved. 3 ** Copyright (C) 2007-2013 Sourcefire, Inc. 4 ** 5 ** This program is free software; you can redistribute it and/or modify 6 ** it under the terms of the GNU General Public License Version 2 as 7 ** published by the Free Software Foundation. You may not use, modify or 8 ** distribute this program under any other version of the GNU General 9 ** Public License. 10 ** 11 ** This program is distributed in the hope that it will be useful, 12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 ** GNU General Public License for more details. 15 ** 16 ** You should have received a copy of the GNU General Public License 17 ** along with this program; if not, write to the Free Software 18 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef __SF_TYPES_H__ 22 #define __SF_TYPES_H__ 23 24 #include <sys/types.h> 25 26 #ifdef HAVE_CONFIG_H 27 #include "config.h" 28 29 #ifdef WIN32 30 # include "stdint.h" 31 # include "inttypes.h" 32 #else 33 /* Autoconf uses <sys/types.h>, <inttypes.h> and <stdint.h> as standard includes for 34 * determining if these exist so there shouldn't be any typedef conflicts with 35 * including <sys/types.h>, <inttypes.h> or <stdint.h> since these would be 36 * defined already */ 37 # if !defined(HAVE_UINT8_T) || !defined(HAVE_U_INT8_T) 38 # if !defined(HAVE_UINT8_T) && !defined(HAVE_U_INT8_T) 39 typedef unsigned char u_int8_t; 40 typedef unsigned char uint8_t; 41 # elif defined(HAVE_UINT8_T) 42 typedef uint8_t u_int8_t; 43 # else 44 typedef u_int8_t uint8_t; 45 # endif /* !defined(HAVE_UINT8_T) && !defined(HAVE_U_INT8_T) */ 46 # endif /* !defined(HAVE_UINT8_T) || !defined(HAVE_U_INT8_T) */ 47 # if !defined(HAVE_UINT16_T) || !defined(HAVE_U_INT16_T) 48 # if !defined(HAVE_UINT16_T) && !defined(HAVE_U_INT16_T) 49 typedef unsigned short u_int16_t; 50 typedef unsigned short uint16_t; 51 # elif defined(HAVE_UINT16_T) 52 typedef uint16_t u_int16_t; 53 # else 54 typedef u_int16_t uint16_t; 55 # endif /* !defined(HAVE_UINT16_T) && !defined(HAVE_U_INT16_T) */ 56 # endif /* !defined(HAVE_UINT16_T) || !defined(HAVE_U_INT16_T) */ 57 # if !defined(HAVE_UINT32_T) || !defined(HAVE_U_INT32_T) 58 # if !defined(HAVE_UINT32_T) && !defined(HAVE_U_INT32_T) 59 # if SIZEOF_UNSIGNED_LONG_INT == 4 60 typedef unsigned long int u_int32_t; 61 typedef unsigned long int uint32_t; 62 # elif SIZEOF_UNSIGNED_INT == 4 63 typedef unsigned int u_int32_t; 64 typedef unsigned int uint32_t; 65 # endif /* SIZEOF_UNSIGNED_LONG_INT == 4 */ 66 # elif defined(HAVE_UINT32_T) 67 typedef uint32_t u_int32_t; 68 # else 69 typedef u_int32_t uint32_t; 70 # endif /* !defined(HAVE_UINT32_T) && !defined(HAVE_U_INT32_T) */ 71 # endif /* !defined(HAVE_UINT32_T) || !defined(HAVE_U_INT32_T) */ 72 # if !defined(HAVE_UINT64_T) || !defined(HAVE_U_INT64_T) 73 # if !defined(HAVE_UINT64_T) && !defined(HAVE_U_INT64_T) 74 # if SIZEOF_UNSIGNED_LONG_LONG_INT == 8 75 typedef unsigned long long int u_int64_t; 76 typedef unsigned long long int uint64_t; 77 # elif SIZEOF_UNSIGNED_LONG_INT == 8 78 typedef unsigned long int u_int64_t; 79 typedef unsigned long int uint64_t; 80 # endif 81 # elif defined(HAVE_UINT64_T) 82 typedef uint64_t u_int64_t; 83 # else 84 typedef u_int64_t uint64_t; 85 # endif /* !defined(HAVE_UINT64_T) && !defined(HAVE_U_INT64_T) */ 86 # endif /* !defined(HAVE_UINT64_T) || !defined(HAVE_U_INT64_T) */ 87 # ifndef HAVE_INT8_T 88 typedef char int8_t; 89 # endif 90 # ifndef HAVE_INT16_T 91 typedef short int16_t; 92 # endif 93 # ifndef HAVE_INT32_T 94 # if SIZEOF_LONG_INT == 4 95 typedef long int int32_t; 96 # else 97 typedef int int32_t; 98 # endif 99 # endif 100 # ifndef HAVE_INT64_T 101 # if SIZEOF_LONG_LONG_INT == 8 102 typedef long long int int64_t; 103 # else 104 typedef long int int64_t; 105 # endif 106 # endif 107 # ifndef WIN32 108 # ifdef HAVE_INTTYPES_H 109 /* <inttypes.h> includes <stdint.h> */ 110 # include <inttypes.h> 111 # elif HAVE_STDINT_H 112 # include <stdint.h> 113 # else 114 /* Solaris - if inttypes.h is present, it should bring this in */ 115 # ifndef SYS_INT_TYPES_H 116 # if defined(_LP64) || defined(_I32LPx) 117 typedef long int intptr_t; 118 typedef unsigned long int uintptr_t; 119 # else 120 typedef int intptr_t; 121 typedef unsigned int uintptr_t; 122 # endif /* defined(_LP64) || defined(_I32LPx) */ 123 # endif /* SYS_INT_TYPES_H */ 124 # endif /* HAVE_INTTYPES_H elseif HAVE_STDINT_H */ 125 # endif 126 #endif /* WIN32 */ 127 #endif /* HAVE_CONFIG_H */ 128 129 /* if PRIu64 isn't in <inttypes.h> 130 * we define it and similar here */ 131 #ifndef PRIu64 132 # if SIZEOF_UNSIGNED_LONG_INT == 8 133 # define _SF_PREFIX "l" 134 # else 135 # define _SF_PREFIX "ll" 136 # endif /* SIZEOF_UNSIGNED_LONG_INT == 8 */ 137 # define PRIu64 _SF_PREFIX "u" 138 # define PRIi64 _SF_PREFIX "i" 139 # define PRIx64 _SF_PREFIX "x" 140 #endif /* PRIu64 */ 141 142 /* use these macros (and those in <inttypes.h>) 143 * for 64 bit format portability 144 */ 145 #define STDu64 "%" PRIu64 146 #define CSVu64 STDu64 "," 147 #define FMTu64(fmt) "%" fmt PRIu64 148 149 #define STDi64 "%" PRIi64 150 #define CSVi64 STDi64 "," 151 #define FMTi64(fmt) "%" fmt PRIi64 152 153 #define STDx64 "%" PRIx64 154 #define CSVx64 STDx64 "," 155 #define FMTx64(fmt) "%" fmt PRIx64 156 157 #ifndef UINT8_MAX 158 # define UINT8_MAX 0xff 159 #endif 160 #ifndef USHRT_MAX 161 # define USHRT_MAX 0xffff 162 #endif 163 #ifndef UINT16_MAX 164 # define UINT16_MAX 0xffff 165 #endif 166 #ifndef UINT32_MAX 167 # define UINT32_MAX (4294967295U) 168 #endif 169 #ifndef UINT64_MAX 170 # if SIZEOF_UNSIGNED_LONG_INT == 8 171 # define UINT64_MAX (18446744073709551615UL) 172 # else 173 # define UINT64_MAX (18446744073709551615ULL) 174 # endif /* SIZEOF_UNSIGNED_LONG_INT == 8 */ 175 #endif /* UINT64_MAX */ 176 177 /* Somewhat arbitrary, but should be enough for this application 178 * since files shouldn't be buried too deep. This provides about 179 * 15 levels of 255 character path components */ 180 #ifndef PATH_MAX 181 # define PATH_MAX 4096 182 #endif 183 184 /* utilities */ 185 #ifndef boolean 186 #ifndef HAVE_BOOLEAN 187 typedef unsigned char boolean; 188 #endif 189 #endif 190 191 #ifndef TRUE 192 # define TRUE 1 193 #endif 194 195 #ifndef FALSE 196 # define FALSE 0 197 #endif 198 199 #ifdef HAVE_STDBOOL_H 200 # include <stdbool.h> 201 #else 202 # ifndef HAVE__BOOL 203 # ifdef __cplusplus 204 typedef bool _Bool; 205 # else 206 # define _Bool signed char 207 # endif 208 # endif 209 # define bool _Bool 210 # define false 0 211 # define true 1 212 # define __bool_true_false_are_defined 1 213 #endif 214 215 #endif /* __SF_TYPES_H__ */ 216 217