Error handling

These functions are used manipulating with error. libcfg+ itself remember last occured error in internal data structures.

#include <cfg+.h>

void cfg_print_error(const CFG_CONTEXT con);

void cfg_fprint_error(const CFG_CONTEXT con, FILE *fh);

char *cfg_get_error_str(const CFG_CONTEXT con);

char *cfg_get_static_error_str(const int errorcode);

Function cfg_print_error() prints error message of last error. Similar function cfg_fprint_error() prints error message to specified stream as second parameter fh.

The last two error manipulating functions returns error message string. First one cfg_get_error_str() returns dynamically allocated NUL array of characters filled with error message. Returned pointer must be freed using free() system call. Second function returns pointer to local static buffer with error message. It needs error code passed as parameter errorcode to work.

In following Error codes table are defined possible error constants returned by parsing function, which has been described in Parsing chapter.

Table 2-4. Error codes

ValueDescription
CFG_ERR_OK, CFG_ERROR_OK, CFG_OK OK, all is right
CFG_ERR_NOARG, CFG_ERROR_NOARG An argument is missing for an option
CFG_ERR_NOTALLOWEDARG, CFG_ERROR_NOTALLOWEDARG An argument is not allowed for an option
CFG_ERR_BADOPT, CFG_ERROR_BADOPT An option's argument could not be parsed
CFG_ERR_BADQUOTE, CFG_ERROR_BADQUOTE Error in quotations
CFG_ERR_BADNUMBER, CFG_ERROR_BADNUMBER An option could not be converted to appropriate numeric type
CFG_ERR_OVERFLOW, CFG_ERROR_OVERFLOW A given number was too big or too small
CFG_ERR_MULTI, CFG_ERROR_MULTI Multiple arguments used for single option
CFG_ERR_NOMEM, CFG_ERROR_NOMEM Not enough memory
CFG_ERR_STOP_STR, CFG_ERR_STOP_STR_FOUND, CFG_ERROR_STOP_STR, CFG_ERROR_STOP_STR_FOUND Stop string was found
CFG_ERR_NOEQUAL, CFG_ERROR_NOEQUAL No equal sign on the line
CFG_ERR_UNKNOWN, CFG_ERROR_UNKNOWN An unknown option
CFG_ERR_FILE_NOT_FOUND, CFG_ERROR_FILE_NOT_FOUND File not found error
CFG_ERR_SEEK_ERROR, CFG_ERROR_SEEK_ERROR Seek error (fseek() failure)
CFG_ERR_INTERNAL, CFG_ERROR_INTERNAL Internal error