GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
sg_get_error(3) sg_get_error(3)

sg_get_error, sg_get_error_arg, sg_get_error_errno, sg_str_error, sg_get_error_details, sg_strperror - get last error status

#include <statgrab.h>


sg_error sg_get_error
(void);


const char *sg_get_error_arg
(void);


int sg_get_error_errno
(void);


sg_error sg_get_error_details
(sg_error_details *err_details);


const char *sg_str_error
(sg_error code);


char *sg_strperror
(char **buf, const sg_error_details * const err_details);

There are four functions to get information about the last occurred error: sg_get_error, sg_get_error_arg, sg_get_error_errno and sg_get_error_details. The remaining functions are intended to improve the machine-human-interface (e.g. the error log or a message box): sg_str_error delivers a human readable error name and sg_strperror prepares a full blown error message for printing.

The error argument (sg_get_error_arg) 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 error_arg of sg_error_details delivered by sg_get_error_details.

When someone calls the function sg_get_error_details with a NULL pointer, the last error is overridden with a new one describing that sg_get_error_details is called with invalid arguments. Please be careful.

The function sg_strperror is allowed to be called with or without (err_details 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 char * lvalue), but the char * lvalue it points to, must be NULL. When invoked correctly, there are only two possible error conditions let sg_strperror fail: ENOMEM (out of memory) and EINVAL (invalid error code).

Example


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);
    }
}
        

The error details contains following information:


typedef struct sg_error_details {
        sg_error error;
        int errno_value;
        const char *error_arg;
} sg_error_details;
    
error
The statgrab library error code.
errno_value
The operating system error code.
error_arg
Additional information set when the error was reported.

statgrab(3)

⟨https://libstatgrab.org/⟩
2019-03-08 libstatgrab

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.