Main Page   Compound List   File List   Compound Members   File Members  

cslutils.h File Reference

#include <csl/csldefs.h>

Go to the source code of this file.

Defines

#define CSL_GNUC_PRINTF(format_idx, arg_idx)
 GCC specific macro. More...

#define CSL_GNUC_NORETURN
 GCC specific macro. More...

#define CSL_UINT_TO_POINTER(ifoo)   ((void*) ((unsigned long) (ifoo)))
 Cast unsigned int to pointer. More...

#define CSL_INT_TO_POINTER(ifoo)   ((void*) ((signed long) (ifoo)))
 Cast int to pointer. More...

#define CSL_POINTER_TO_INT(pfoo)   ((int) ((signed long) (pfoo)))
 Cast pointer to int. More...

#define CSL_POINTER_TO_UINT(pfoo)   ((unsigned int) ((unsigned long) (pfoo)))
 Cast pointer to unsigned int. More...

#define csl_new(struct, n)   (csl_malloc (sizeof (struct) * n))
 Allocate storage for structs. More...

#define csl_new0(struct, n)   (csl_malloc0 (sizeof (struct) * n))
 Allocate and clear storage for structs. More...

#define csl_assert(cond)   { if (!(cond)) csl_error ("assertion failed: %s", # cond ); }
 Assertion check. More...

#define csl_return_if_fail(cond)   { if (!(cond)) { csl_warning ("assertion failed: %s", # cond ); return; } }
 Assertion check with return. More...

#define csl_return_val_if_fail(cond, v)   { if (!(cond)) { csl_warning ("assertion failed: %s", # cond ); return (v); } }
 Assertion check with return of a value. More...

#define csl_debug(key)   (csl_check_debug (CSL_DEBUG_ ## key))
 Check debug level. More...


Enumerations

enum  CslDebugFlags { CSL_DEBUG_NONE = (0), CSL_DEBUG_PCM = (1 << 0), CSL_DEBUG_MISC = (1 << 1) }
 Debugging levels. More...


Functions

void csl_error (const char *format,...) CSL_GNUC_PRINTF(1, 2) CSL_GNUC_NORETURN
 Display error message. More...

void csl_warning (const char *format,...) CSL_GNUC_PRINTF(1, 2)
 Display warning message. More...

void csl_message (const char *format,...) CSL_GNUC_PRINTF(1, 2)
 Display informational message. More...

void csl_free (void *mem)
 Free dynamically allocated memory. More...

void * csl_malloc (unsigned int n_bytes)
 Dynamically allocate memory. More...

void * csl_malloc0 (unsigned int n_bytes)
 Dynamically allocate and clear memory. More...

void * csl_realloc (void *mem, unsigned int n_bytes)
 Change size of dynamically allocated memory. More...

void * csl_memdup (void const *mem, unsigned int n_bytes)
char * csl_strdup (const char *string)
 Duplicate a string. More...

void csl_strfreevn (unsigned int n, char **str_p)
 Free a group of strings. More...

void csl_set_debug_mask (unsigned int debug_mask)
 Set debugging level. More...

CslBool csl_check_debug (unsigned int debug_key)
 Check debug level. More...


Detailed Description

This file defines some useful utility functions that can be used in CSL.


Define Documentation

#define CSL_GNUC_NORETURN
 

GCC specific macro.

#define CSL_GNUC_PRINTF format_idx,
arg_idx   
 

GCC specific macro.

#define CSL_INT_TO_POINTER ifoo       ((void*) ((signed long) (ifoo)))
 

Cast int to pointer.

#define CSL_POINTER_TO_INT pfoo       ((int) ((signed long) (pfoo)))
 

Cast pointer to int.

#define CSL_POINTER_TO_UINT pfoo       ((unsigned int) ((unsigned long) (pfoo)))
 

Cast pointer to unsigned int.

#define CSL_UINT_TO_POINTER ifoo       ((void*) ((unsigned long) (ifoo)))
 

Cast unsigned int to pointer.

#define csl_assert cond       { if (!(cond)) csl_error ("assertion failed: %s", # cond ); }
 

Assertion check.

Check if a condition is true, and if not, call csl_error with a suitable error message.

Parameters:
cond  An expression to be evaluated
See also:
csl_error , csl_return_if_fail , csl_return_val_if_fail

#define csl_debug key       (csl_check_debug (CSL_DEBUG_ ## key))
 

Check debug level.

Return whether the specified debug level is enabled. e.g. csl_check_debug(PCM);

Parameters:
debug_key  A debug level, specified as either PCM or NONE.
Returns:
TRUE if the given debug level is enabled, otherwise FALSE.
See also:
csl_check_debug , csl_debug

#define csl_new struct,
     (csl_malloc (sizeof (struct) * n))
 

Allocate storage for structs.

Allocate storage for one or more variables of type struct.

Parameters:
struct  The type name of the struct.
n  The number of struct variables to allocate.
Returns:
A pointer to the newly allocated memory.
See also:
csl_new0 , csl_free

#define csl_new0 struct,
     (csl_malloc0 (sizeof (struct) * n))
 

Allocate and clear storage for structs.

Allocate storage for one or more variables of type struct and fill the memory with zeroes.

Parameters:
struct  The type name of the struct.
n  The number of struct variables to allocate.
Returns:
A pointer to the newly allocated memory.
See also:
csl_new , csl_free

#define csl_return_if_fail cond       { if (!(cond)) { csl_warning ("assertion failed: %s", # cond ); return; } }
 

Assertion check with return.

Check if a condition is true, and if not, call csl_warning and return.

Parameters:
cond  An expression to be evaluated
See also:
csl_warning , csl_assert , csl_return_val_if_fail

#define csl_return_val_if_fail cond,
     { if (!(cond)) { csl_warning ("assertion failed: %s", # cond ); return (v); } }
 

Assertion check with return of a value.

Check if a condition is true, and if not, call csl_warning and return a value.

Parameters:
cond  An expression to be evaluated
v  Value to be returned if assertion fails
See also:
csl_return_if_fail , csl_return_val_if_fail


Enumeration Type Documentation

enum CslDebugFlags
 

Debugging levels.

You can enable debug messages for PCM and/or miscellaneous functions.

See also:
csl_set_debug_mask , csl_debug , csl_check_debug
Enumeration values:
CSL_DEBUG_NONE 
CSL_DEBUG_PCM 
CSL_DEBUG_MISC 


Function Documentation

CslBool csl_check_debug unsigned int    debug_key
 

Check debug level.

Return whether the specified debug level is enabled. e.g. csl_check_debug(CSL_DEBUG_PCM);

Parameters:
debug_key  One of the elements of the enumerated type CslDebugFlags.
Returns:
TRUE if the given debug level is enabled, otherwise FALSE.
See also:
csl_set_debug_mask , csl_debug

void csl_error const char *    format,
...   
 

Display error message.

Display an error message on standard error and then exit using abort().

Parameters:
format  A printf() style format string optionally followed by additional arguments. Does not return.
See also:
csl_warning , csl_message

void csl_free void *    mem
 

Free dynamically allocated memory.

Free memory previously allocated by csl_malloc, csl_malloc0, csl_malloc0, csl_new, or csl_new0.

Parameters:
mem  Pointer to previously allocated memory.
Returns:
none
See also:
csl_malloc , csl_malloc0 , csl_realloc , csl_new , csl_new0

void* csl_malloc unsigned int    n_bytes
 

Dynamically allocate memory.

Dynamically allocate storage. Calls csl_error if memory cannot be allocated.

Parameters:
n_bytes  The number of bytes of storage to be dynamically allocated.
Returns:
A pointer to the allocated memory.
See also:
csl_free , csl_malloc0 , csl_realloc , csl_new , csl_new0

void* csl_malloc0 unsigned int    n_bytes
 

Dynamically allocate and clear memory.

Dynamically allocate storage. Calls csl_error if memory cannot be allocated. Sets the allocated memory to all zeroes.

Parameters:
n_bytes  The number of bytes of storage to be dynamically allocated.
Returns:
A pointer to the allocated memory.
See also:
csl_free , csl_malloc0 , csl_realloc , csl_new , csl_new0

void* csl_memdup void const *    mem,
unsigned int    n_bytes
 

void csl_message const char *    format,
...   
 

Display informational message.

Display an informational message on standard error.

Parameters:
format  A printf() style format string optionally followed by additional arguments.
Returns:
none
See also:
csl_error , csl_warning

void* csl_realloc void *    mem,
unsigned int    n_bytes
 

Change size of dynamically allocated memory.

Changes the size of dynamically allocate storage. Calls csl_error if memory cannot be allocated.

Parameters:
mem  Pointer to the start of the previously allocated storage. If NULL, the call is equivalent to calling csl_malloc.
n_bytes  The new size of the area of storage to be dynamically allocated, which can be greater or smaller than the current size. If n_bytes is zero, then the call is equivalent to calling csl_free.
Returns:
A pointer to the new area of allocated memory.
See also:
csl_free , csl_malloc , csl_malloc0 , csl_new , csl_new0

void csl_set_debug_mask unsigned int    debug_mask
 

Set debugging level.

Set level of debug messages to be displayed. e.g. csl_set_debug_mask(CSL_DEBUG_PCM|CSL_DEBUG_MISC);

Parameters:
debug_mask  Debug flags, one or more of the elements of the enumerated type CslDebugFlags, ORed together.
See also:
csl_check_debug , csl_debug

char* csl_strdup const char *    string
 

Duplicate a string.

Returns a pointer to a new string which is a duplicate of string. Memory for the new string is obtained with csl_malloc and can be freed with csl_free.

Parameters:
string  Pointer to the original string
Returns:
A pointer to the new string
See also:
csl_free , csl_strfreevn

void csl_strfreevn unsigned int    n,
char **    str_p
 

Free a group of strings.

A group of strings pointed to by pointers stored sequentially in memory are freed using csl_free.

Parameters:
n  Number of string pointers to be freed.
str_p  Pointer to start of a series of pointers to strings to be freed.
See also:
csl_free

void csl_warning const char *    format,
...   
 

Display warning message.

Display a warning message on standard error.

Parameters:
format  A printf() style format string optionally followed by additional arguments.
Returns:
none
See also:
csl_error , csl_message


Generated on Wed Oct 31 18:45:21 2001 for CSL by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001