Error handling
The information about the last occurred error is stored within the context in
the CFG_CONTEXT structure. The following functions
provide a convenient interface for interpreting, querying and printing that
information.
]]>
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
The function cfg_print_error() prints an error message
describing the last error. To print the message to the specified stream, use
cfg_fprint_error(), which takes a stream pointer
fh as its second argument.
Lastly, cfg_get_error_str(), returns an error message in
a dynamically allocated string. Be sure to free the memory taken by the string
when you do not need it anymore.
The following table describes the error constants
used by the parsing functions. See section for reference.
Error codes
Value
Description
CFG_OK
Everything is OK
CFG_ERROR_NOARG
An argument is missing for the option
CFG_ERROR_NOTALLOWEDARG
An argument is not allowed for the option
CFG_ERROR_BADOPT
The option's argument could not be parsed
CFG_ERROR_BADQUOTE
Error in quotations
CFG_ERROR_BADNUMBER
The option could not be converted to an appropriate numeric type
CFG_ERROR_OVERFLOW
A given numeric value was too big or too small
CFG_ERROR_MULTI
Multiple arguments used for an option that takes only one argument
CFG_ERROR_NOMEM
Not enough memory
CFG_ERROR_STOP_STR,
CFG_ERROR_STOP_STR_FOUND
Stop string was found
CFG_ERROR_NOEQUAL
Equal sign expected on the line, but no one was found
CFG_ERROR_UNKNOWN
An unknown option
CFG_ERROR_FILE_NOT_FOUND
File not found
CFG_ERROR_SEEK_ERROR
Seek error (fseek() failure)
CFG_ERROR_INTERNAL
Internal error
All of the constants have an alternative, short form, which can be derived by
replacing _ERROR_ with _ERR_ in the
name of the constant. So for example you can use
CFG_ERR_BADOPT as a substitution for
CFG_ERROR_BADOPT.