00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CSL_UTILS_H__
00020 #define __CSL_UTILS_H__
00021
00022 #include <csl/csldefs.h>
00023
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027
00033
00034
00035 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
00036
00037 #define CSL_GNUC_PRINTF( format_idx, arg_idx ) \
00038 __attribute__((format (printf, format_idx, arg_idx)))
00039
00040 #define CSL_GNUC_NORETURN \
00041 __attribute__((noreturn))
00042 #else
00043
00044 #define CSL_GNUC_PRINTF( format_idx, arg_idx )
00045
00046 #define CSL_GNUC_NORETURN
00047 #endif
00048
00049
00050
00051
00053 #define CSL_UINT_TO_POINTER(ifoo) ((void*) ((unsigned long) (ifoo)))
00054
00055 #define CSL_INT_TO_POINTER(ifoo) ((void*) ((signed long) (ifoo)))
00056
00057 #define CSL_POINTER_TO_INT(pfoo) ((int) ((signed long) (pfoo)))
00058
00059 #define CSL_POINTER_TO_UINT(pfoo) ((unsigned int) ((unsigned long) (pfoo)))
00060
00061
00062
00063 void csl_error (const char *format,
00064 ...) CSL_GNUC_PRINTF (1, 2) CSL_GNUC_NORETURN;
00065 void csl_warning (const char *format,
00066 ...) CSL_GNUC_PRINTF (1, 2);
00067 void csl_message (const char *format,
00068 ...) CSL_GNUC_PRINTF (1, 2);
00069 void csl_free (void *mem);
00070 void* csl_malloc (unsigned int n_bytes);
00071 void* csl_malloc0 (unsigned int n_bytes);
00072 void* csl_realloc (void *mem,
00073 unsigned int n_bytes);
00074 char* csl_strdup (const char *string);
00075 void csl_strfreevn (unsigned int n,
00076 char **str_p);
00077
00078
00089 #define csl_new(struct, n) (csl_malloc (sizeof (struct) * n))
00090
00102 #define csl_new0(struct, n) (csl_malloc0 (sizeof (struct) * n))
00103
00104
00105
00115 #define csl_assert(cond) { if (!(cond)) csl_error ("assertion failed: %s", # cond ); }
00116
00126 #define csl_return_if_fail(cond) { if (!(cond)) { csl_warning ("assertion failed: %s", # cond ); return; } }
00127
00137 #define csl_return_val_if_fail(cond, v) { if (!(cond)) { csl_warning ("assertion failed: %s", # cond ); return (v); } }
00138
00139
00140
00141
00149 typedef enum
00150 {
00151 CSL_DEBUG_NONE = (0),
00152 CSL_DEBUG_PCM = (1 << 0),
00153 CSL_DEBUG_MISC = (1 << 1)
00154 } CslDebugFlags;
00155
00156 void csl_set_debug_mask (unsigned int debug_mask);
00157
00158 CslBool csl_check_debug (unsigned int debug_key);
00159
00170 #define csl_debug(key) (csl_check_debug (CSL_DEBUG_ ## key))
00171
00172 #ifdef __cplusplus
00173 }
00174 #endif
00175
00176 #endif