Get last error status
\*(T<#include <statgrab.h>\*(T>
\*(T<sg_error sg_get_error\*(T> \kx \*(T<(void);\*(T>
\*(T<const char *sg_get_error_arg\*(T> \kx \*(T<(void);\*(T>
\*(T<int sg_get_error_errno\*(T> \kx \*(T<(void);\*(T>
\*(T<sg_error sg_get_error_details\*(T> \kx \*(T<(sg_error_details *err_details);\*(T>
\*(T<const char *sg_str_error\*(T> \kx \*(T<(sg_error code);\*(T>
\*(T<char *sg_strperror\*(T> \kx \*(T<(char **buf, const sg_error_details * const err_details);\*(T>
There are four functions to get information about the last occurred error: \*(T<sg_get_error\*(T>, \*(T<sg_get_error_arg\*(T>, \*(T<sg_get_error_errno\*(T> and \*(T<sg_get_error_details\*(T>. The remaining functions are intended to improve the machine-human-interface (e.g. the error log or a message box): \*(T<sg_str_error\*(T> delivers a human readable error name and \*(T<sg_strperror\*(T> prepares a full blown error message for printing.
The error argument (\*(T<sg_get_error_arg\*(T>) is stored thread local and is reused every time an error occures. If a later usage is intended, duplicating it is a suitable strategy. Same for the \*(T<error_arg\*(T> of \*(T<sg_error_details\*(T> delivered by \*(T<sg_get_error_details\*(T>.
When someone calls the function \*(T<sg_get_error_details\*(T> with a NULL pointer, the last error is overridden with a new one describing that \*(T<sg_get_error_details\*(T> is called with invalid arguments. Please be careful.
The function \*(T<sg_strperror\*(T> is allowed to be called with or without (\*(T<err_details\*(T> is NULL) collected error details. In the latter case, the last occurred error of this thread is used to prepare the error message. Be aware, the the buffer pointer must be non-NULL (points to an existing \*(T<char *\*(T> lvalue), but the \*(T<char *\*(T> lvalue it points to, must be NULL. When invoked correctly, there are only two possible error conditions let \*(T<sg_strperror\*(T> fail: ENOMEM (out of memory) and EINVAL (invalid error code).
Example
\*(T< if( NULL == sg_get_cpu_stats() ) { char *buf = NULL; if( NULL != sg_strperror( &buf, NULL ) ) { fprintf( stderr, "error getting CPU stats: %s\n", buf ); free(buf); exit(255); } else { fprintf( stderr, "error getting CPU stats and error information\n" ); exit(255); } } \*(T>
The error details contains following information:
\*(T< typedef struct sg_error_details { sg_error error; int errno_value; const char *error_arg; } sg_error_details; \*(T>
\*(T<error\*(T>
The statgrab library error code.
\*(T<errno_value\*(T>
The operating system error code.
\*(T<error_arg\*(T>
Additional information set when the error was reported.
statgrab(3)
\(lahttp://www.i-scream.org/libstatgrab/\(ra