cslutils.h Source File

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 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 /* --- debugging assertions --- */
    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 /* --- debugging messages --- */
    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 /* __cplusplus */
    00177
    00178 #endif /* __CSL_UTILS_H__ */