1 /* 2 * Copyright 2004-2007, 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 /* this must be located before the include of sys/types.h */ 13 #if !defined(_SYS_TYPES_H) && !defined(_SYS_TYPES_H_) 14 typedef unsigned long ulong; 15 typedef unsigned int uint; 16 typedef unsigned short ushort; 17 #endif 18 19 #include <BeBuild.h> 20 #include <Errors.h> 21 22 #include <sys/types.h> 23 24 25 // Shorthand type formats 26 typedef signed char int8; 27 typedef unsigned char uint8; 28 typedef volatile signed char vint8; 29 typedef volatile unsigned char vuint8; 30 31 typedef short int16; 32 typedef unsigned short uint16; 33 typedef volatile short vint16; 34 typedef volatile unsigned short vuint16; 35 36 typedef long int32; 37 typedef unsigned long uint32; 38 typedef volatile long vint32; 39 typedef volatile unsigned long vuint32; 40 41 typedef long long int64; 42 typedef unsigned long long uint64; 43 typedef volatile long long vint64; 44 typedef volatile unsigned long long vuint64; 45 46 typedef volatile long vlong; 47 typedef volatile int vint; 48 typedef volatile short vshort; 49 typedef volatile char vchar; 50 51 typedef volatile unsigned long vulong; 52 typedef volatile unsigned int vuint; 53 typedef volatile unsigned short vushort; 54 typedef volatile unsigned char vuchar; 55 56 typedef unsigned char uchar; 57 typedef unsigned short unichar; 58 59 60 // Descriptive formats 61 typedef int32 status_t; 62 typedef int64 bigtime_t; 63 typedef uint32 type_code; 64 typedef uint32 perform_code; 65 66 67 // Empty string ("") 68 #ifdef __cplusplus 69 extern const char *B_EMPTY_STRING; 70 #endif 71 72 73 // min and max comparisons 74 #ifndef __cplusplus 75 # ifndef min 76 # define min(a,b) ((a)>(b)?(b):(a)) 77 # endif 78 # ifndef max 79 # define max(a,b) ((a)>(b)?(a):(b)) 80 # endif 81 #endif 82 83 // min() and max() won't work in C++ 84 #define min_c(a,b) ((a)>(b)?(b):(a)) 85 #define max_c(a,b) ((a)>(b)?(a):(b)) 86 87 88 // Grandfathering 89 #ifndef __cplusplus 90 # include <stdbool.h> 91 #endif 92 93 #ifndef NULL 94 # define NULL (0) 95 #endif 96 97 98 #ifdef __cplusplus 99 extern "C" { 100 #endif 101 102 // Atomic functions; previous value is returned 103 extern int32 atomic_set(vint32 *value, int32 newValue); 104 extern int32 atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst); 105 extern int32 atomic_add(vint32 *value, int32 addValue); 106 extern int32 atomic_and(vint32 *value, int32 andValue); 107 extern int32 atomic_or(vint32 *value, int32 orValue); 108 extern int32 atomic_get(vint32 *value); 109 110 extern int64 atomic_set64(vint64 *value, int64 newValue); 111 extern int64 atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst); 112 extern int64 atomic_add64(vint64 *value, int64 addValue); 113 extern int64 atomic_and64(vint64 *value, int64 andValue); 114 extern int64 atomic_or64(vint64 *value, int64 orValue); 115 extern int64 atomic_get64(vint64 *value); 116 117 // Other stuff 118 extern void* get_stack_frame(void); 119 120 #ifdef __cplusplus 121 } 122 #endif 123 124 // Obsolete or discouraged API 125 126 // use 'true' and 'false' 127 #ifndef FALSE 128 # define FALSE 0 129 #endif 130 #ifndef TRUE 131 # define TRUE 1 132 #endif 133 134 #endif // _SUPPORT_DEFS_H 135