1 /* 2 * Copyright 2004-2010, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Author: 6 * Erik Jaesler (erik@cgsoftware.com) 7 */ 8 #ifndef _SUPPORT_DEFS_H 9 #define _SUPPORT_DEFS_H 10 11 12 #include <config_build/types.h> 13 14 #include <BeBuild.h> 15 #include <Errors.h> 16 17 #include <inttypes.h> 18 #include <sys/types.h> 19 20 21 /* fixed-size integer types */ 22 typedef __haiku_int8 int8; 23 typedef __haiku_uint8 uint8; 24 typedef __haiku_int16 int16; 25 typedef __haiku_uint16 uint16; 26 typedef __haiku_int32 int32; 27 typedef __haiku_uint32 uint32; 28 typedef __haiku_int64 int64; 29 typedef __haiku_uint64 uint64; 30 31 /* shorthand types */ 32 typedef volatile int8 vint8; 33 typedef volatile uint8 vuint8; 34 typedef volatile int16 vint16; 35 typedef volatile uint16 vuint16; 36 typedef volatile int32 vint32; 37 typedef volatile uint32 vuint32; 38 typedef volatile int64 vint64; 39 typedef volatile uint64 vuint64; 40 41 typedef volatile long vlong; 42 typedef volatile int vint; 43 typedef volatile short vshort; 44 typedef volatile char vchar; 45 46 typedef volatile unsigned long vulong; 47 typedef volatile unsigned int vuint; 48 typedef volatile unsigned short vushort; 49 typedef volatile unsigned char vuchar; 50 51 typedef unsigned char uchar; 52 typedef unsigned short unichar; 53 54 /* descriptive types */ 55 typedef int32 status_t; 56 typedef int64 bigtime_t; 57 typedef uint32 type_code; 58 typedef uint32 perform_code; 59 60 61 /* printf()/scanf() format strings for [u]int* types */ 62 #define B_PRId8 PRId8 63 #define B_PRIi8 PRIi8 64 #define B_PRId16 PRId16 65 #define B_PRIi16 PRIi16 66 #define B_PRId32 PRId32 67 #define B_PRIi32 PRIi32 68 #define B_PRId64 PRId64 69 #define B_PRIi64 PRIi64 70 #define B_PRIu8 PRIu8 71 #define B_PRIo8 PRIo8 72 #define B_PRIx8 PRIx8 73 #define B_PRIX8 PRIX8 74 #define B_PRIu16 PRIu16 75 #define B_PRIo16 PRIo16 76 #define B_PRIx16 PRIx16 77 #define B_PRIX16 PRIX16 78 #define B_PRIu32 PRIu32 79 #define B_PRIo32 PRIo32 80 #define B_PRIx32 PRIx32 81 #define B_PRIX32 PRIX32 82 #define B_PRIu64 PRIu64 83 #define B_PRIo64 PRIo64 84 #define B_PRIx64 PRIx64 85 #define B_PRIX64 PRIX64 86 87 #define B_SCNd8 SCNd8 88 #define B_SCNi8 SCNi8 89 #define B_SCNd16 SCNd16 90 #define B_SCNi16 SCNi16 91 #define B_SCNd32 SCNd32 92 #define B_SCNi32 SCNi32 93 #define B_SCNd64 SCNd64 94 #define B_SCNi64 SCNi64 95 #define B_SCNu8 SCNu8 96 #define B_SCNo8 SCNo8 97 #define B_SCNx8 SCNx8 98 #define B_SCNu16 SCNu16 99 #define B_SCNu16 SCNu16 100 #define B_SCNx16 SCNx16 101 #define B_SCNu32 SCNu32 102 #define B_SCNo32 SCNo32 103 #define B_SCNx32 SCNx32 104 #define B_SCNu64 SCNu64 105 #define B_SCNo64 SCNo64 106 #define B_SCNx64 SCNx64 107 108 109 /* printf() format strings for some standard types */ 110 /* size_t */ 111 #define B_PRIuSIZE B_PRIu32 112 #define B_PRIoSIZE B_PRIo32 113 #define B_PRIxSIZE B_PRIx32 114 #define B_PRIXSIZE B_PRIX32 115 /* ssize_t */ 116 #define B_PRIdSSIZE B_PRId32 117 #define B_PRIiSSIZE B_PRIi32 118 /* addr_t */ 119 #ifdef HAIKU_HOST_PLATFORM_64_BIT 120 # define B_PRIuADDR B_PRIu64 121 # define B_PRIoADDR B_PRIo64 122 # define B_PRIxADDR B_PRIx64 123 # define B_PRIXADDR B_PRIX64 124 #else 125 # define B_PRIuADDR B_PRIu32 126 # define B_PRIoADDR B_PRIo32 127 # define B_PRIxADDR B_PRIx32 128 # define B_PRIXADDR B_PRIX32 129 #endif 130 /* phys_addr_t */ 131 #ifdef HAIKU_HOST_PLATFORM_64_BIT 132 # define B_PRIuPHYSADDR B_PRIu64 133 # define B_PRIoPHYSADDR B_PRIo64 134 # define B_PRIxPHYSADDR B_PRIx64 135 # define B_PRIXPHYSADDR B_PRIX64 136 #else 137 # define B_PRIuPHYSADDR B_PRIu32 138 # define B_PRIoPHYSADDR B_PRIo32 139 # define B_PRIxPHYSADDR B_PRIx32 140 # define B_PRIXPHYSADDR B_PRIX32 141 #endif 142 /* off_t */ 143 #define B_PRIdOFF B_PRId64 144 #define B_PRIiOFF B_PRIi64 145 /* dev_t */ 146 #define B_PRIdDEV B_PRId32 147 #define B_PRIiDEV B_PRIi32 148 /* ino_t */ 149 #define B_PRIdINO B_PRId64 150 #define B_PRIiINO B_PRIi64 151 /* time_t */ 152 #define B_PRIdTIME B_PRId32 153 #define B_PRIiTIME B_PRIi32 154 155 156 /* Empty string ("") */ 157 #ifdef __cplusplus 158 extern const char *B_EMPTY_STRING; 159 #endif 160 161 162 /* min and max comparisons */ 163 #ifndef __cplusplus 164 # ifndef min 165 # define min(a,b) ((a)>(b)?(b):(a)) 166 # endif 167 # ifndef max 168 # define max(a,b) ((a)>(b)?(a):(b)) 169 # endif 170 #endif 171 172 /* min() and max() are functions in C++ */ 173 #define min_c(a,b) ((a)>(b)?(b):(a)) 174 #define max_c(a,b) ((a)>(b)?(a):(b)) 175 176 177 /* Grandfathering */ 178 #ifndef __cplusplus 179 # include <stdbool.h> 180 #endif 181 182 #ifndef NULL 183 # define NULL (0) 184 #endif 185 186 187 #ifdef __cplusplus 188 extern "C" { 189 #endif 190 191 /* Atomic functions; previous value is returned */ 192 extern int32 atomic_set(vint32 *value, int32 newValue); 193 extern int32 atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst); 194 extern int32 atomic_add(vint32 *value, int32 addValue); 195 extern int32 atomic_and(vint32 *value, int32 andValue); 196 extern int32 atomic_or(vint32 *value, int32 orValue); 197 extern int32 atomic_get(vint32 *value); 198 199 extern int64 atomic_set64(vint64 *value, int64 newValue); 200 extern int64 atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst); 201 extern int64 atomic_add64(vint64 *value, int64 addValue); 202 extern int64 atomic_and64(vint64 *value, int64 andValue); 203 extern int64 atomic_or64(vint64 *value, int64 orValue); 204 extern int64 atomic_get64(vint64 *value); 205 206 /* Other stuff */ 207 extern void* get_stack_frame(void); 208 209 #ifdef __cplusplus 210 } 211 #endif 212 213 /* Obsolete or discouraged API */ 214 215 /* use 'true' and 'false' */ 216 #ifndef FALSE 217 # define FALSE 0 218 #endif 219 #ifndef TRUE 220 # define TRUE 1 221 #endif 222 223 #endif /* _SUPPORT_DEFS_H */ 224