Common error codes and error handling functions


Files

file  errstr.c
 Error string handling for l4env.

Data Structures

struct  l4env_err_msg_t
 Error message table entry. More...
struct  l4env_err_desc
 Structure for registering multiple error message tables. More...
struct  l4env_err_fn_desc
 Structure for registering an error-string function. More...

Defines

#define L4ENV_ERR_DESC_(vis, name, arr...)
 Declare error message table.
#define L4ENV_ERR_DESC(name, arr...)   L4ENV_ERR_DESC_(,name,arr)
 Construct a description of error codes.
#define L4ENV_ERR_DESC_STATIC(name, arr...)   L4ENV_ERR_DESC_(static,name,arr)
 Construct a description of error code, static version.
#define L4ENV_ERR_FN_DESC_(vis, name, fn, unknown_string)
 Declare error-string function.
#define L4ENV_ERR_FN_DESC(name, fn, unknown_string)   L4ENV_ERR_FN_DESC_(,name,fn,unknown_string)
 Construct a description for an error string function.
#define L4ENV_ERR_FN_DESC_STATIC(name, fn, unknown_string)   L4ENV_ERR_FN_DESC_(static,name,fn,unknown_string)
 Construct a description for an error string function, static version.
#define l4env_errstr(retcode)   l4env_strerror(-retcode)
 Show error message for return code.
#define l4env_perror(string, errcode, opts...)   LOG_Error(string ": %s" ,##opts, l4env_strerror(errcode))
 Print an error message containing an l4env error string.

Typedefs

typedef struct l4env_err_desc l4env_err_desc_t
 Structure for registering multiple error message tables.
typedef struct l4env_err_fn_desc l4env_err_fn_desc_t
 Structure for registering an error-string function.

Functions

L4_CV int l4env_err_register_fn (l4env_err_fn_desc_t *fn_desc)
 Register an error-function.
L4_CV int l4env_err_register_desc (l4env_err_desc_t *desc)
 Register an error-description structure containing error-codes and messages.
L4_CV const char * l4env_strerror (int code)
 Return string describing error code.

Variables

const char * l4env_err_unknown
 Unknown error message string.

Define Documentation

#define L4ENV_ERR_DESC_ ( vis,
name,
arr...   ) 

Value:

static l4env_err_msg_t l4env_err_description_##name[]={arr};      \
  vis l4env_err_desc_t name = { NULL,                               \
                              sizeof(l4env_err_description_##name)  \
                                  / sizeof(l4env_err_msg_t),        \
                              l4env_err_description_##name}
Declare error message table.

Parameters:
vis Error table scope (global or static)
name Error table name
arr Error table definition (l4env_err_msg_t array)

#define L4ENV_ERR_DESC ( name,
arr...   )     L4ENV_ERR_DESC_(,name,arr)

Construct a description of error codes.

Parameters:
name Error table name
arr Error table definition (l4env_err_msg_t array)

#define L4ENV_ERR_DESC_STATIC ( name,
arr...   )     L4ENV_ERR_DESC_(static,name,arr)

Construct a description of error code, static version.

Parameters:
name Error table name
arr Error table definition (l4env_err_msg_t array)

#define L4ENV_ERR_FN_DESC_ ( vis,
name,
fn,
unknown_string   ) 

Value:

vis l4env_err_fn_desc_t name={                  \
                NULL,                                   \
                fn,                                     \
                unknown_string, -1}
Declare error-string function.

Parameters:
vis Descriptor scope (global or static)
name Descriptor name
fn Error string function
unknown_string Error string for unknown error codes

#define L4ENV_ERR_FN_DESC ( name,
fn,
unknown_string   )     L4ENV_ERR_FN_DESC_(,name,fn,unknown_string)

Construct a description for an error string function.

Parameters:
name Descriptor name
fn Error string function
unknown_string Error string for unknown error codes

#define L4ENV_ERR_FN_DESC_STATIC ( name,
fn,
unknown_string   )     L4ENV_ERR_FN_DESC_(static,name,fn,unknown_string)

Construct a description for an error string function, static version.

Parameters:
name Descriptor name
fn Error string function
unknown_string Error string for unknown error codes

#define l4env_errstr ( retcode   )     l4env_strerror(-retcode)

Show error message for return code.

#define l4env_perror ( string,
errcode,
opts...   )     LOG_Error(string ": %s" ,##opts, l4env_strerror(errcode))

Print an error message containing an l4env error string.

Parameters:
string The main format string. May contain printf- format specifiers. AAn ": %s\n" will be appended.
code The error code. It will be passed to l4env_strerror() and given as last argument to the string formatter.
opts Optional arguments for the format specifiers in string.
Precondition:
Requires liblog to be linked, which is the case with l4env normally.


Typedef Documentation

Structure for registering multiple error message tables.

Structure for registering an error-string function.


Function Documentation

int l4env_err_register_fn ( l4env_err_fn_desc_t fn_desc  ) 

Register an error-function.

Parameters:
fn_desc description of the function
fn_desc->fn the function
fn_desc->unknown string returned by fn in case of an unknown error code (or the first characters of it)
fn_desc->unknown_len -1
Return values:
0 success
\c -L4_EINVAL fn_desc or the function is invalid (0)
The error-function in fn_desc will be called from l4env_strerror() to obtain a string describing a given error code. fn_desc->fn should return either the string description, or a string whose characters compare against fn_desc->unknown. In the latter case, the code is assumed to be unknown to the function in fn_desc and l4env_strerror() will use the other registered functions.

You can use the macros L4ENV_ERR_FN_DESC and L4ENV_ERR_FN_DESC_STATIC to easily construct fn_desc.

Due to the large searching space, l4env_err_register_fn() does not perform checks if the codes valid to fn_desc->fn are already registerd/used.

int l4env_err_register_desc ( l4env_err_desc_t desc  ) 

Register an error-description structure containing error-codes and messages.

Parameters:
desc the description
Return values:
0 success
\c -L4_EUSED at least one of the codes in arr is already registered
l4env_err_register_desc() registers error-codes and messages. desc can be constructed using the L4ENV_ERR_DESC macro.

Prior to registering, this function checks if all of the codes in desc are unregistered so far. This means, they can not be found in the registerd array, nor returns any of the registered functions a valid error-string.

const char * l4env_strerror ( int  code  ) 

Return string describing error code.

Parameters:
code the error code
Returns:
a string describing the error. If the error-code is unknown (unregistered), l4env_err_unknown is returned.
This function performs a search for the given code in the registered arrays and functions. The search begins within the arrays. The search order within the arrays does not matter, because they are distinct. The search order within the functions is not defined.

If the return value is not l4env_err_unknown, the returned string can only be used until the next call to l4env_strerror().

Note:
As in strerror(), the given error code is not the (mostly negative) return value of service-functions, but the error code as defined in the several errno.h's. This means, the caller must negate the return-value of these functions, if they return error-codes in their negated form.


Variable Documentation

const char* l4env_err_unknown

Unknown error message string.


Generated on Wed Apr 11 06:39:52 2012 for L4 Environment Library by  doxygen 1.5.6