Main Page   Compound List   File List   Compound Members   File Members  

cslutils.h

Go to the documentation of this file.
00001 /* CSL - Common Sound Layer
00002  * Copyright (C) 2000-2001 Stefan Westerfeld and Tim Janik
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General
00015  * Public License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00017  * Boston, MA 02111-1307, USA.
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 /* __cplusplus */
00027 
00033 /* --- GCC specific macros --- */
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 /* --- portable conversions --- */
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 /* --- standard utility functions --- */
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 /* --- debugging assertions --- */
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 /* --- debugging messages --- */
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 /* __cplusplus */
00175 
00176 #endif /* __CSL_UTILS_H__ */

Generated at Wed Jun 6 17:51:41 2001 for CSL by doxygen1.2.8 written by Dimitri van Heesch, © 1997-2001