1 /* 2 * Copyright 2004-2009, 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/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 /* off_t */ 131 #define B_PRIdOFF B_PRId64 132 #define B_PRIiOFF B_PRIi64 133 /* dev_t */ 134 #define B_PRIdDEV B_PRId32 135 #define B_PRIiDEV B_PRIi32 136 /* ino_t */ 137 #define B_PRIdINO B_PRId64 138 #define B_PRIiINO B_PRIi64 139 /* time_t */ 140 #define B_PRIdTIME B_PRId32 141 #define B_PRIiTIME B_PRIi32 142 143 144 /* Empty string ("") */ 145 #ifdef __cplusplus 146 extern const char *B_EMPTY_STRING; 147 #endif 148 149 150 /* min and max comparisons */ 151 #ifndef __cplusplus 152 # ifndef min 153 # define min(a,b) ((a)>(b)?(b):(a)) 154 # endif 155 # ifndef max 156 # define max(a,b) ((a)>(b)?(a):(b)) 157 # endif 158 #endif 159 160 /* min() and max() are functions in C++ */ 161 #define min_c(a,b) ((a)>(b)?(b):(a)) 162 #define max_c(a,b) ((a)>(b)?(a):(b)) 163 164 165 /* Grandfathering */ 166 #ifndef __cplusplus 167 # include <stdbool.h> 168 #endif 169 170 #ifndef NULL 171 # define NULL (0) 172 #endif 173 174 175 #ifdef __cplusplus 176 extern "C" { 177 #endif 178 179 /* Atomic functions; previous value is returned */ 180 extern int32 atomic_set(vint32 *value, int32 newValue); 181 extern int32 atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst); 182 extern int32 atomic_add(vint32 *value, int32 addValue); 183 extern int32 atomic_and(vint32 *value, int32 andValue); 184 extern int32 atomic_or(vint32 *value, int32 orValue); 185 extern int32 atomic_get(vint32 *value); 186 187 extern int64 atomic_set64(vint64 *value, int64 newValue); 188 extern int64 atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst); 189 extern int64 atomic_add64(vint64 *value, int64 addValue); 190 extern int64 atomic_and64(vint64 *value, int64 andValue); 191 extern int64 atomic_or64(vint64 *value, int64 orValue); 192 extern int64 atomic_get64(vint64 *value); 193 194 /* Other stuff */ 195 extern void* get_stack_frame(void); 196 197 #ifdef __cplusplus 198 } 199 #endif 200 201 /* Obsolete or discouraged API */ 202 203 /* use 'true' and 'false' */ 204 #ifndef FALSE 205 # define FALSE 0 206 #endif 207 #ifndef TRUE 208 # define TRUE 1 209 #endif 210 211 #endif /* _SUPPORT_DEFS_H */ 212