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 void* csl_memdup (void const *mem,
00075 unsigned int n_bytes);
00076 char* csl_strdup (const char *string);
00077 void csl_strfreevn (unsigned int n,
00078 char **str_p);
00079
00080
00091 #define csl_new(struct, n) (csl_malloc (sizeof (struct) * n))
00092
00104 #define csl_new0(struct, n) (csl_malloc0 (sizeof (struct) * n))
00105
00106
00107
00117 #define csl_assert(cond) { if (!(cond)) csl_error ("assertion failed: %s", # cond ); }
00118
00128 #define csl_return_if_fail(cond) { if (!(cond)) { csl_warning ("assertion failed: %s", # cond ); return; } }
00129
00139 #define csl_return_val_if_fail(cond, v) { if (!(cond)) { csl_warning ("assertion failed: %s", # cond ); return (v); } }
00140
00141
00142
00143
00151 typedef enum
00152 {
00153 CSL_DEBUG_NONE = (0),
00154 CSL_DEBUG_PCM = (1 << 0),
00155 CSL_DEBUG_MISC = (1 << 1)
00156 } CslDebugFlags;
00157
00158 void csl_set_debug_mask (unsigned int debug_mask);
00159
00160 CslBool csl_check_debug (unsigned int debug_key);
00161
00172 #define csl_debug(key) (csl_check_debug (CSL_DEBUG_ ## key))
00173
00174 #ifdef __cplusplus
00175 }
00176 #endif
00177
00178 #endif