1sg_get_error(3)                                                sg_get_error(3)
2
3
4

NAME

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

SYNOPSIS

10       #include <statgrab.h>
11
12
13       sg_error sg_get_error (void);
14
15       const char *sg_get_error_arg (void);
16
17       int sg_get_error_errno (void);
18
19       sg_error sg_get_error_details (sg_error_details *err_details);
20
21       const char *sg_str_error (sg_error code);
22
23       char *sg_strperror (char **buf, const sg_error_details * const
24                          err_details);
25

DESCRIPTION

27       There are four functions to get information about the last occurred er‐
28       ror: sg_get_error, sg_get_error_arg, sg_get_error_errno and  sg_get_er‐
29       ror_details.  The  remaining  functions are intended to improve the ma‐
30       chine-human-interface  (e.g.   the  error  log  or  a   message   box):
31       sg_str_error delivers a human readable error name and sg_strperror pre‐
32       pares a full blown error message for printing.
33
34       The error argument (sg_get_error_arg) is stored  thread  local  and  is
35       reused  every  time an error occures. If a later usage is intended, du‐
36       plicating it is a suitable strategy. Same for the error_arg  of  sg_er‐
37       ror_details delivered by sg_get_error_details.
38
39       When someone calls the function sg_get_error_details with a NULL point‐
40       er, the last error  is  overridden  with  a  new  one  describing  that
41       sg_get_error_details  is called with invalid arguments. Please be care‐
42       ful.
43
44       The function sg_strperror is allowed  to  be  called  with  or  without
45       (err_details  is NULL) collected error details. In the latter case, the
46       last occurred error of this thread is used to prepare  the  error  mes‐
47       sage.  Be  aware, the the buffer pointer must be non-NULL (points to an
48       existing char * lvalue), but the char * lvalue it points  to,  must  be
49       NULL.  When invoked correctly, there are only two possible error condi‐
50       tions let sg_strperror fail: ENOMEM (out of memory) and EINVAL (invalid
51       error code).
52
53       Example
54
55       if( NULL == sg_get_cpu_stats() ) {
56           char *buf = NULL;
57           if( NULL != sg_strperror( &buf, NULL ) ) {
58               fprintf( stderr, "error getting CPU stats: %s\n", buf );
59               free(buf);
60               exit(255);
61           }
62           else {
63               fprintf( stderr, "error getting CPU stats and error information\n" );
64               exit(255);
65           }
66       }
67
68

RETURN VALUES

70       The error details contains following information:
71
72       typedef struct sg_error_details {
73               sg_error error;
74               int errno_value;
75               const char *error_arg;
76       } sg_error_details;
77
78
79       error  The statgrab library error code.
80
81       errno_value
82              The operating system error code.
83
84       error_arg
85              Additional information set when the error was reported.
86

SEE ALSO

88       statgrab(3)
89

WEBSITE

91http://www.i-scream.org/libstatgrab/
92
93
94
95i-scream                          2013-06-07                   sg_get_error(3)
Impressum