utils/kp_error.c File Reference

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "kp_error.h"
#include "kp_errors_define_decl.txt"

Data Structures

struct  kp_error_s
 KP error structure. More...

Defines

#define KP_ERRORS_LIST_END_CODE   -666
 Using with kp_errors_list (.
#define KP_ERROR_DECLARATION(enum_code_decl, code_value, error_text)   { enum_code_decl, error_text },
#define KP_ERROR_DECLARATION_LAST(enum_code_decl, code_value, error_text)   { enum_code_decl, error_text },

Typedefs

typedef struct kp_error_s kp_error_t
 KP error structure.

Functions

int set_error (int error_code)
 Sets code of error.
int get_error_code ()
 Return code of error.
int get_error_code_and_reset ()
 Return code of error and reset error.
const char * get_error_text ()
 Return error message.
char * get_error_text_and_reset ()
 Return error message and reset error.
const char * get_error_text_by_code (int error_code)
 Gets error message by error code.
int reset_error ()
 Sets code of error equals 0 (no errors) and message equals empty string.

Define Documentation

#define KP_ERROR_DECLARATION ( enum_code_decl,
code_value,
error_text   )     { enum_code_decl, error_text },

#define KP_ERROR_DECLARATION_LAST ( enum_code_decl,
code_value,
error_text   )     { enum_code_decl, error_text },

#define KP_ERRORS_LIST_END_CODE   -666

Using with kp_errors_list (.

See also:
kp_errors_list) as last element in the array.


Typedef Documentation

typedef struct kp_error_s kp_error_t

KP error structure.


Function Documentation

int get_error_code (  ) 

Return code of error.

Returns:
code of error.

int get_error_code_and_reset (  ) 

Return code of error and reset error.

Returns:
code of error.

const char* get_error_text (  ) 

Return error message.

Returns:
error description.

char* get_error_text_and_reset (  ) 

Return error message and reset error.

Return error message and reset error. You need free message text after using.

Returns:
error description.

const char* get_error_text_by_code ( int  error_code  ) 

Gets error message by error code.

Parameters:
error_code code of error.
Returns:
error description.

int reset_error (  ) 

Sets code of error equals 0 (no errors) and message equals empty string.

Returns:
ERROR_NO code (equals 0), usefull for end function, if no errors (return reset_error()).

int set_error ( int  error_code  ) 

Sets code of error.

Parameters:
error_code code of error.
Returns:
given error code(usefull for end of function: return set_error(code))


doxygen