CAPS Universe documentation
1.0.4
All you need to know to be successful
|
How to deal with error messages. More...
Functions | |
int | caps_cl_error_messages_catch (struct caps_cl_handle *instance, char **ptr, size_t *size) |
void | caps_cl_error_messages_reset (struct caps_cl_handle *instance) |
Usually the error messages are handled by libcapsbase and are sent to stderr by default. For a console tool or a background process this might be a good choice. For a somehow graphical interactive application it makes more sense to be able to present the error message to the user.
Enable this feature immediately after the client instance creation and libcapsclient forwards all error messages to this buffer instead. If you catch an error code by one of the client functions, the buffer will contain a corresponding error message terminated by a '\0' character. This message uses the current locale and so, the error message might be already translated to the local language. If you like more the size of the string instead of the terminating '\0' character, you can use the size_t
variable instead. Refer the manual page of the open_memstream() for details.
It is in your responsibility to manage the used buffer. The memory was dynamically allocated and needs to be freed after use.
In your program it looks like that:
int caps_cl_error_messages_catch | ( | struct caps_cl_handle * | instance, |
char ** | ptr, | ||
size_t * | size | ||
) |
Setup a self growing storage to catch error messages
[in,out] | instance | Client instance |
[out] | ptr | Where to store the base address of the buffer |
[out] | size | Where to store the buffer size |
0 | Error catching successfully initialized |
negative | errno from the open_memstream() call |
If your local ptr is still NULL or your local size is still '0', then no error messages were created. Else the memory was dynamically allocated and needs to be freed after use. The buffer contains a '\0' terminated string.
void caps_cl_error_messages_reset | ( | struct caps_cl_handle * | instance | ) |
Reset the error message buffer
[in,out] | instance | Client instance |
If you have processed an error message, you can reset the buffer for the next error message.