1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2004-2005, Haiku 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: SupportDefs.h 23 // Author: Erik Jaesler (erik@cgsoftware.com) 24 // Description: Common type definitions. 25 //------------------------------------------------------------------------------ 26 27 #ifndef _SUPPORT_DEFS_H 28 #define _SUPPORT_DEFS_H 29 30 /* this !must! be located before the include of sys/types.h */ 31 #if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_) 32 typedef unsigned long ulong; 33 typedef unsigned int uint; 34 typedef unsigned short ushort; 35 #endif 36 37 38 // Standard Includes ----------------------------------------------------------- 39 40 // System Includes ------------------------------------------------------------- 41 #include <BeBuild.h> 42 #include <sys/types.h> 43 #include <Errors.h> 44 45 // Shorthand type formats ------------------------------------------------------ 46 47 typedef signed char int8; 48 typedef unsigned char uint8; 49 typedef volatile signed char vint8; 50 typedef volatile unsigned char vuint8; 51 52 typedef short int16; 53 typedef unsigned short uint16; 54 typedef volatile short vint16; 55 typedef volatile unsigned short vuint16; 56 57 typedef long int32; 58 typedef unsigned long uint32; 59 typedef volatile long vint32; 60 typedef volatile unsigned long vuint32; 61 62 typedef long long int64; 63 typedef unsigned long long uint64; 64 typedef volatile long long vint64; 65 typedef volatile unsigned long long vuint64; 66 67 typedef volatile long vlong; 68 typedef volatile int vint; 69 typedef volatile short vshort; 70 typedef volatile char vchar; 71 72 typedef volatile unsigned long vulong; 73 typedef volatile unsigned int vuint; 74 typedef volatile unsigned short vushort; 75 typedef volatile unsigned char vuchar; 76 77 typedef unsigned char uchar; 78 typedef unsigned short unichar; 79 80 81 // Descriptive formats --------------------------------------------------------- 82 typedef int32 status_t; 83 typedef int64 bigtime_t; 84 typedef uint32 type_code; 85 typedef uint32 perform_code; 86 87 88 // Empty string ("") ----------------------------------------------------------- 89 #ifdef __cplusplus 90 extern _IMPEXP_BE const char *B_EMPTY_STRING; 91 #endif 92 93 94 // min and max comparisons ----------------------------------------------------- 95 // min() and max() won't work in C++ 96 #define min_c(a,b) ((a)>(b)?(b):(a)) 97 #define max_c(a,b) ((a)>(b)?(a):(b)) 98 99 #ifndef __cplusplus 100 # ifndef min 101 # define min(a,b) ((a)>(b)?(b):(a)) 102 # endif 103 # ifndef max 104 # define max(a,b) ((a)>(b)?(a):(b)) 105 # endif 106 #endif 107 108 109 // Grandfathering -------------------------------------------------------------- 110 #ifndef __cplusplus 111 # include <stdbool.h> 112 #endif 113 114 #ifndef NULL 115 # define NULL (0) 116 #endif 117 118 119 //------------------------------------------------------------------------------ 120 #ifdef __cplusplus 121 extern "C" { 122 #endif 123 124 //----- Atomic functions; old value is returned -------------------------------- 125 extern _IMPEXP_ROOT int32 atomic_set(vint32 *value, int32 newValue); 126 extern _IMPEXP_ROOT int32 atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst); 127 extern _IMPEXP_ROOT int32 atomic_add(vint32 *value, int32 addValue); 128 extern _IMPEXP_ROOT int32 atomic_and(vint32 *value, int32 andValue); 129 extern _IMPEXP_ROOT int32 atomic_or(vint32 *value, int32 orValue); 130 extern _IMPEXP_ROOT int32 atomic_get(vint32 *value); 131 132 extern _IMPEXP_ROOT int64 atomic_set64(vint64 *value, int64 newValue); 133 extern _IMPEXP_ROOT int64 atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst); 134 extern _IMPEXP_ROOT int64 atomic_add64(vint64 *value, int64 addValue); 135 extern _IMPEXP_ROOT int64 atomic_and64(vint64 *value, int64 andValue); 136 extern _IMPEXP_ROOT int64 atomic_or64(vint64 *value, int64 orValue); 137 extern _IMPEXP_ROOT int64 atomic_get64(vint64 *value); 138 139 // Other stuff ----------------------------------------------------------------- 140 extern _IMPEXP_ROOT void * get_stack_frame(void); 141 142 #ifdef __cplusplus 143 } 144 #endif 145 146 //-------- Obsolete or discouraged API ----------------------------------------- 147 148 // use 'true' and 'false' 149 #ifndef FALSE 150 # define FALSE 0 151 #endif 152 #ifndef TRUE 153 # define TRUE 1 154 #endif 155 156 #endif // _SUPPORT_DEFS_H 157